Skip to content
Snippets Groups Projects
Commit b986e764 authored by gyan000's avatar gyan000
Browse files

Import code

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 486 additions and 0 deletions
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* gyan000 <gyan000 (at] ijaz.fr>
*/
using MConnect;
namespace EOSConnect.Views {
public class DeviceSettingsView : Granite.SimpleSettingsPage {
public Widgets.DeviceListBox device_list_box { get; construct; }
public Device device { get; construct; }
public MainWindow main_window { get; construct; }
public DeviceSettingsView (Device device, Widgets.DeviceListBox device_list_box, MainWindow main_window) {
Object (
activatable: true,
description: device.name, // always original device name here.
icon_name: "phone",
title: "",
device: device,
device_list_box: device_list_box,
main_window: main_window
);
}
construct {
var custom_name = device.name;
if (device.custom_name.length > 1) {
custom_name = device.settings.get_string ("custom-name");
}
title = custom_name;
icon_name = Tools.get_icon_name (Tools.get_icon_name (device.device_type));
if(device.is_paired) {
status_switch.active = true;
}
var custom_name_label = new Gtk.Label (_("Custom name"));
custom_name_label.xalign = 1;
var custom_name_entry = new Gtk.Entry ();
custom_name_entry.hexpand = true;
custom_name_entry.placeholder_text = custom_name;
var plugin_list_box = new Widgets.PluginListBox (
device,
main_window
);
plugin_list_box.update_ui (device.plugins_map);
var scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window.expand = true;
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
scrolled_window.add (plugin_list_box);
content_area.attach (custom_name_label, 0, 1, 1, 1);
content_area.attach (custom_name_entry, 1, 1, 1, 1);
content_area.attach (scrolled_window, 0, 4, 4, 3);
margin = 12;
show_all ();
device.settings.bind ("custom-name", custom_name_entry, "text", SettingsBindFlags.DEFAULT);
status_switch.notify["active"].connect (() => {
if (status_switch.active) {
// ClientIface.get_instance ().allow_device.begin (device.id);
} else {
// ClientIface.get_instance ().disallow_device.begin (device.id);
}
});
custom_name_entry.changed.connect (() => {
title = custom_name_entry.text;
device.custom_name = custom_name_entry.text;
device_list_box.update_selected_list_box_row ();
});
}
public void update_ui () {
if(device.is_paired) {
status_switch.active = true;
}
}
}
}
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* gyan000 <gyan000 (at] ijaz.fr>
*/
using Gee;
using Granite.Widgets;
using MConnect;
namespace EOSConnect.Views {
public class DevicesView : Gtk.Frame {
public MainWindow main_window { get; construct; }
public Widgets.DeviceListBox device_list_box { public get; private set; }
private Gtk.Stack _stack;
private Widgets.DeviceListActionBarFooter device_list_action_bar_footer;
private string _latest_id_selected = null;
public DevicesView (MainWindow main_window) {
Object (
main_window: main_window
);
}
construct {
var scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window.expand = true;
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
device_list_box = new Widgets.DeviceListBox ();
scrolled_window.add (device_list_box);
device_list_action_bar_footer = new Widgets.DeviceListActionBarFooter (main_window);
var sidebar_grid = new Gtk.Grid ();
sidebar_grid.orientation = Gtk.Orientation.VERTICAL;
sidebar_grid.add (scrolled_window);
sidebar_grid.add (device_list_action_bar_footer);
_stack = new Gtk.Stack ();
_stack.set_transition_type (Gtk.StackTransitionType.CROSSFADE);
var paned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
paned.pack1 (sidebar_grid, true, false);
paned.pack2 (_stack, true, false);
margin = 12;
add (paned);
device_list_box.row_selected.connect (_device_list_selected);
}
public void update_device_list (HashMap<string, Device> devices_map) {
foreach (var entry in devices_map.entries) {
_add_device_settings (entry.value);
bool device_already_in_list_box = false;
int count = 0;
device_list_box.@foreach (() => {
Widgets.DeviceListBoxRow device_list_box_row = (Widgets.DeviceListBoxRow)device_list_box.get_row_at_index (count);
if (device_list_box_row.device.id == entry.value.id) {
device_already_in_list_box = true;
// Make sure we keep current selected device like the previous.. selected device.
if(device_list_box_row.device.id == _latest_id_selected) {
device_list_box.select_row (device_list_box.get_row_at_index (count));
}
((Widgets.DeviceListBoxRow)device_list_box.get_row_at_index(count)).update_ui ();
}
count++;
});
if (device_already_in_list_box == false) {
device_list_box.insert (new Widgets.DeviceListBoxRow (entry.value), count);
}
}
// First time we populate the list box.
if (device_list_box.get_selected_row () == null && _latest_id_selected == null) {
device_list_box.select_row (device_list_box.get_row_at_index (0));
_latest_id_selected = ((Widgets.DeviceListBoxRow)device_list_box.get_row_at_index (0)).device.id;
}
show_all ();
}
private void _add_device_settings (Device device) {
if (_stack.get_child_by_name (device.id) == null) {
DeviceSettingsView device_settings_view = new DeviceSettingsView (device, device_list_box, main_window);
device_settings_view.width_request = 150;
debug ("Adding DeviceSettingsView Widget for device '%s'".printf (device.name));
_stack.add_named (device_settings_view, device.id);
} else {
((DeviceSettingsView)_stack.get_child_by_name (device.id)).update_ui ();
}
}
private void _device_list_selected (Gtk.ListBoxRow? device_item) {
Device? device = null;
if (device_item != null) {
device = ((Widgets.DeviceListBoxRow)device_item).device;
_latest_id_selected = device.id;
_stack.set_visible_child_name (device.id);
device_list_action_bar_footer.update_ui (device);
}
}
}
}
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* gyan000 <gyan000 (at] ijaz.fr>
*/
namespace EOSConnect.Views {
public class MainSettingsView : Gtk.Stack {
public MainWindow main_window { get; construct; }
public GLib.Settings main_settings { get; construct; }
public MainSettingsView (MainWindow main_window, GLib.Settings main_settings) {
Object (
main_settings: main_settings,
main_window: main_window
);
}
construct {
var sms_store_row = new OptionListBoxRow (
new OptionImage("mail-mark-read"),
new OptionLabelTitle (_("Store SMS")),
new OptionLabelDescription (_("Active / Deactivate the storage of SMS for all devices.")),
new OptionSwitch (_("Active / Deactivate the storage of SMS for all devices."),
"kdeconnect-telephony-store-sms-globally-active", _main_settings));
var list_box = new Gtk.ListBox ();
list_box.insert (sms_store_row, 0);
var scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window.expand = true;
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
scrolled_window.add (list_box);
margin = 12;
add(scrolled_window);
}
private class OptionImage : Gtk.Image {
public OptionImage (string icon_name) {
set_from_icon_name (icon_name, Gtk.IconSize.DND);
pixel_size = 32;
}
}
private class OptionLabelTitle : Gtk.Label {
public OptionLabelTitle (string text) {
label = text;
xalign = 0;
ellipsize = Pango.EllipsizeMode.END;
get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
}
}
private class OptionLabelDescription: Gtk.Label {
public OptionLabelDescription (string text) {
label = text;
ellipsize = Pango.EllipsizeMode.END;
hexpand = true;
xalign = 0;
}
}
private class OptionSwitch: Gtk.Switch {
public OptionSwitch (string tooltip, string settings_key, GLib.Settings main_settings) {
tooltip_text = tooltip;
valign = Gtk.Align.CENTER;
active = main_settings.get_boolean (settings_key);
main_settings.bind (settings_key, this, "active", SettingsBindFlags.DEFAULT);
}
}
private class OptionListBoxRow : Gtk.ListBoxRow {
public OptionListBoxRow (
OptionImage image,
OptionLabelTitle label_title,
OptionLabelDescription label_description,
OptionSwitch switch
) {
var grid = new Gtk.Grid ();
grid.margin = 6;
grid.column_spacing = 12;
grid.attach (image, 0, 0, 1, 2);
grid.attach (label_title, 1, 0, 1, 1);
grid.attach (label_description, 1, 1, 1, 1);
grid.attach (@switch, 2, 0, 1, 2);
add (grid);
}
}
}
}
This diff is collapsed.
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* gyan000 <gyan000 (at] ijaz.fr>
*/
using MConnect;
namespace EOSConnect.Widgets {
public class DeviceListActionBarFooter : Gtk.ActionBar {
public MainWindow main_window { get; construct; }
private Gtk.Button button_remove;
public DeviceListActionBarFooter (MainWindow main_window) {
Object (main_window: main_window);
}
construct {
button_remove = new Gtk.Button.from_icon_name ("list-remove-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
button_remove.sensitive = false;
button_remove.tooltip_text = _("Forget selected device");
var refresh_devices_button = new Gtk.Button.from_icon_name ("view-refresh");
refresh_devices_button.tooltip_text = _("Refresh devices");
get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR);
add (refresh_devices_button);
add (button_remove);
button_remove.clicked.connect (() => {
debug ("@TODO - remove device.");
});
refresh_devices_button.clicked.connect (() => {
// main_window.display_overlaybar (_("Searching for devices..."));
// ClientIface.get_instance ().get_device_list.begin ();
});
}
public void update_ui (Device device) {
button_remove.sensitive = false;
// if (device.is_paired == false && device.is_connected == false) {
// button_remove.sensitive = true;
// }
}
}
}
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* gyan000 <gyan000 (at] ijaz.fr>
*/
using MConnect;
namespace EOSConnect.Widgets {
public class DeviceListBox : Gtk.ListBox {
private Gtk.Label _devices_label;
construct {
selection_mode = Gtk.SelectionMode.SINGLE;
set_header_func (update_headers);
_devices_label = new Gtk.Label (_("Devices"));
_devices_label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);
_devices_label.halign = Gtk.Align.START;
show_all ();
}
public void update_selected_list_box_row () {
var list_box_row = (DeviceListBoxRow)this.get_selected_row ();
list_box_row.update_ui ();
}
private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) {
if(before == null) {
row.set_header (_devices_label);
}
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*-
* Copyright (c) 2015 Wingpanel Developers (http://launchpad.net/wingpanel)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* gyan000 <gyan000 (at] ijaz.fr>
*
* Original code:
* https://github.com/elementary/wingpanel-indicator-notifications/blob/master/src/Services/Notification.vala
*/
[DBus (name = "org.freedesktop.Notifications")]
public interface DBusNotificationsInterface : Object {
public signal void notification_closed (uint32 id, uint32 reason);
public signal void action_invoked (string action, uint32 id);
public abstract uint32 notify (string app_name,
uint32 replaces_id,
string app_icon,
string summary,
string body,
string[] actions,
HashTable<string, Variant> hints,
int32 expire_timeout) throws Error;
}
[DBus (name = "org.freedesktop.DBus")]
public interface DBusInterface : Object {
[DBus (name = "NameHasOwner")]
public abstract bool name_has_owner (string name) throws Error;
[DBus (name = "GetConnectionUnixProcessID")]
public abstract uint32 get_connection_unix_process_id (string name) throws Error;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment