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 1703 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 EOSConnect;
using MConnect;
namespace EOSConnect.Plugin.Popover {
public class ShareSettings : Gtk.Popover {
public Device device { get; construct; }
public ShareSettings (Device device, Gtk.Widget? relative_to) {
Object (
device: device,
relative_to: relative_to,
modal: true,
position: Gtk.PositionType.BOTTOM
);
}
construct {
var share_icon = new Gtk.Image.from_icon_name ("emblem-shared", Gtk.IconSize.DND);
share_icon.pixel_size = 64;
share_icon.margin = 5;
var desc_label = new Granite.HeaderLabel (_("Download directory"));
var file_chooser = new Gtk.FileChooserButton (_("Select default download directory"),
Gtk.FileChooserAction.SELECT_FOLDER);
file_chooser.margin_right = 10;
var directory = device.settings.get_string ("kdeconnect-share-directory");
if (directory.length > 5) {
file_chooser.set_uri (directory);
} else {
file_chooser.set_uri (ShareHandler.DOWNLOADS);
}
// left, top, width, height
var grid = new Gtk.Grid ();
grid.attach (share_icon, 0, 0, 1, 3);
grid.attach (desc_label, 1, 0, 3, 1);
grid.attach (file_chooser, 1, 1, 5, 1);
add (grid);
file_chooser.selection_changed.connect (() => {
device.settings.set_string ("kdeconnect-share-directory", file_chooser.get_uri ());
});
}
}
}
/**
* 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 EOSConnect;
using MConnect;
namespace EOSConnect.Plugin.Popover {
public class TelephonySettings : Gtk.Popover {
public Device device { get; construct; }
public TelephonySettings (Device device, Gtk.Widget? relative_to) {
Object (
device: device,
relative_to: relative_to,
modal: true,
position: Gtk.PositionType.BOTTOM
);
}
construct {
var history_icon = new Gtk.Image.from_icon_name ("mail-mark-read", Gtk.IconSize.DND);
history_icon.pixel_size = 64;
history_icon.margin = 5;
//history_icon.sensitive = device.settings.get_boolean ("kdeconnect-battery-notify-low-level-active");
var desc_label = new Granite.HeaderLabel (_("Store SMS"));
var history_day_label = new Gtk.Label (_("Number of days of history"));
history_day_label.halign = Gtk.Align.START;
history_day_label.margin = 10;
//history_day_label.sensitive = device.settings.get_boolean ("kdeconnect-battery-notify-low-level-active");
var history_day_spin = new Gtk.SpinButton.with_range (
(double)1, (double)99, (double)1);
history_day_spin.halign = Gtk.Align.CENTER;
history_day_spin.hexpand = false;
history_day_spin.margin = 10;
//history_day_spin.value = device.settings.get_double("kdeconnect-battery-low-level-treshold");
// device.settings.bind ("kdeconnect-battery-low-level-treshold", history_day_spin,
// "value", SettingsBindFlags.DEFAULT);
var activation_switch = new Gtk.Switch ();
activation_switch.tooltip_text = _("Activate / Deactivate history");
activation_switch.halign = Gtk.Align.END;
activation_switch.hexpand = false;
activation_switch.margin = 10;
// device.settings.bind ("kdeconnect-battery-notify-low-level-active", activation_switch,
// "active", SettingsBindFlags.DEFAULT);
// history_day_spin.sensitive = device.settings.get_boolean ("kdeconnect-battery-notify-low-level-active");
// left, top, width, height1
var grid = new Gtk.Grid ();
grid.attach (history_icon, 0, 0, 1, 3);
grid.attach (desc_label, 1, 0, 3, 1);
grid.attach (history_day_label, 1, 1, 1, 1);
grid.attach (history_day_spin, 2, 1, 1, 1);
grid.attach (activation_switch, 3, 1, 1, 1);
add (grid);
activation_switch.notify["active"].connect( () => {
// ((Plugin.Battery)device.plugins_map.@get (BatteryHandler.BATTERY))
// .battery_low_level_notify_is_active = activation_switch.active;
history_icon.sensitive = activation_switch.active;
history_day_label.sensitive = activation_switch.active;
history_day_spin.sensitive = activation_switch.active;
});
// history_day_spin.notify["value"].connect( () => {
// ((Plugin.Battery)device.plugins_map.@get (BatteryHandler.BATTERY))
// .battery_low_level_notify_treshold = history_day_spin.value;
// });
}
}
}
/**
* 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.Plugin {
public class SMS : Object {
public const int FROM_TYPE_TELEPHONY = 1;
public const int FROM_TYPE_NOTIFICATION = 2;
public const int FROM_TYPE_EOSCONNECT = 3;
public const int FROM_CONTACT = 1;
public const int FROM_ME = 2;
public SMSContact? sms_contact;
public string message { get; private set; default = ""; }
public int from { get; private set; default = FROM_CONTACT; }
public int from_type { get; private set; default = FROM_TYPE_TELEPHONY; }
public DateTime date_time { get; private set; }
public SMS (string message,
int from,
int from_type,
DateTime date_time) {
this.message = message;
this.from = from;
this.from_type = from_type;
this.date_time = date_time;
}
}
}
/**
* 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.Plugin {
public class SMSContact : Object {
public string custom_name;
public string contact_image_path;
public string phone_thumbnail;
public string contact_name { get; private set; default = ""; }
public string phone_number { get; private set; default = ""; }
public string device_id { get; private set; default = ""; }
public SMSContact (string phone_number,
string contact_name,
string device_id,
string phone_thumbnail,
string custom_name) {
this.phone_number = phone_number;
this.contact_name = contact_name;
this.device_id = device_id;
this.phone_thumbnail = phone_thumbnail;
this.custom_name = custom_name;
this.contact_image_path = "";
}
public bool set_contact_image () {
string file_pathname = "/tmp/eos-connect-sms-contact-" + phone_number;
try {
if (FileUtils.test (file_pathname, FileTest.IS_REGULAR)) {
debug ("Contact image cached: %s", file_pathname);
contact_image_path = file_pathname;
return true;
}
if (phone_thumbnail.length > 10) {
FileUtils.set_data (file_pathname, Base64.decode (phone_thumbnail));
contact_image_path = file_pathname;
phone_thumbnail = null;
debug ("Contact image cache generated: %s", contact_image_path);
}
} catch (Error e) {
warning ("Error: %s", e.message);
contact_image_path = "";
return false;
}
return 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>
*/
namespace EOSConnect.Plugin {
public class SMSStore : GLib.Object {
private static SMSStoreInterface? sms_store_interface_instance = null;
public static SMSStoreInterface instance (GLib.Settings ?main_settings = null) {
if (sms_store_interface_instance == null) {
sms_store_interface_instance = SMSStoreFactory.get_sms_store (main_settings);
}
return sms_store_interface_instance;
}
}
}
/**
* 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.Plugin {
public abstract class SMSStoreFactory : Object {
public static SMSStoreInterface get_sms_store (GLib.Settings ?main_settings) {
if (main_settings == null) {
warning ("Something is wrong here, for the instantiation, we should have a GLib.Settings, will use SMSStoreTemp by default.");
return new SMSStoreTemp ();
}
if (main_settings.get_boolean ("kdeconnect-telephony-store-sms-globally-active") == true) {
info ("Using SMSStoreSQLite.");
SMSStoreSQLite sms_sqlite = new SMSStoreSQLite ();
sms_sqlite.main_settings = main_settings;
sms_sqlite.init_store ();
if (sms_sqlite.is_initialized == true &&
main_settings.get_boolean ("kdeconnect-telephony-db-setup-done") == false) {
if (sms_sqlite.initial_setup () == true) {
main_settings.set_boolean ("kdeconnect-telephony-db-setup-done", true);
}
}
return sms_sqlite;
}
info ("Using SMSStoreTemp.");
SMSStoreTemp sms_temp = new SMSStoreTemp ();
sms_temp.main_settings = main_settings;
return sms_temp;
}
}
}
/**
* 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 MConnect;
namespace EOSConnect.Plugin {
public abstract class SMSStoreInterface : Object {
public signal void sms_handled (SMS sms);
public signal void contacts_updated (HashMap<string, SMSContact> sms_contact_map);
public signal void contact_updated (SMSContact sms_contact);
public bool is_initialized { public get; protected set; default = true; }
public GLib.Settings main_settings;
public HashMap<string, SMSContact> sms_contact_map { protected set; get; }
public HashMap<string, SMS> sms_map { protected set; get; }
public SMSStoreInterface () {
sms_contact_map = new HashMap<string, SMSContact> ();
sms_map = new HashMap<string, SMS> ();
}
public abstract void add_sms (Device device, SMS sms, SMSContact sms_contact);
public virtual bool initial_setup () {
debug ("This store does not provide an initial_setup method.");
return true;
}
public virtual void init_store () {
debug ("This store does not provide an init_store method.");
}
public virtual Gee.ArrayList<SMS> get_latest_sms_message (SMSContact sms_contact) {
debug ("This store does not provide a get_latest_sms_message method.");
return new Gee.ArrayList<SMS> ();
}
public virtual Gee.ArrayList<SMS> get_previous_sms_message (SMSContact sms_contact, DateTime before_date_tim) {
debug ("This store does not provide aget_latest_sms_message method.");
return new Gee.ArrayList<SMS> ();
}
public virtual void handle_missed_sms (Device device, SMS sms, string contact_name) {
debug ("This store does not provide a handle_missed_sms method.");
}
public virtual void refresh_contact_list () {
debug ("This store does not provide a refresh_contact_list method.");
}
public virtual void merge_contact (Contact contact) {
debug ("This store does not provide a merge_contact method.");
}
}
}
/**
* 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 MConnect;
using Sqlite;
namespace EOSConnect.Plugin {
public class SMSStoreSQLite : SMSStoreInterface {
private const int COL_CONTACT_PHONE = 0;
private const int COL_CONTACT_THUMBNAIL = 1;
private const int COL_CONTACT_NAME = 2;
private const int COL_CONTACT_CUSTOM_NAME = 3;
private const int COL_CONTACT_DEVICE_ID = 4;
private const int COL_MESSAGE_TEXT = 1;
private const int COL_MESSAGE_DATE_RECEIVED = 3;
private const int COL_MESSAGE_FROM = 4;
private const int COL_MESSAGE_FROM_TYPE = 5;
private Database _db;
private string _error_msg;
private int _error_code;
public override void add_sms (Device device, SMS sms, SMSContact sms_contact) {
if (sms_contact_map.@has_key (sms_contact.phone_number) == false) {
debug ("Adding new contact.");
string query = "INSERT OR IGNORE INTO contact (phone_number, phone_thumbnail, ";
query += "name, custom_name, from_device_id) ";
query += "VALUES('" + sms_contact.phone_number + "', '" + _res (sms_contact.phone_thumbnail) + "', ";
query += "'" + _res (sms_contact.contact_name) + "', '" + _res (sms_contact.contact_name) + "', ";
query += "'" + device.id + "');";
_exec_query (query);
sms_contact.set_contact_image ();
sms_contact_map.@set (sms_contact.phone_number, sms_contact);
contacts_updated (sms_contact_map);
}
debug ("Adding SMS in DB.");
sms.sms_contact = sms_contact;
string query = "INSERT INTO message (contact_phone_number, message, from_device_id, ";
query += "date_received, `from`, from_type) ";
query += "VALUES ('" + sms_contact.phone_number + "', '" + _res (sms.message) + "', ";
query += "'" + device.id + "', '" + sms.date_time.to_string () + "', ";
query += "'" + sms.from.to_string () + "', '" + sms.from_type.to_string () + "');";
_exec_query (query);
sms.sms_contact = sms_contact;
sms_handled (sms);
return;
}
public override bool initial_setup () {
debug ("Creating tables.");
string query = """
CREATE TABLE contact (
phone_number TEXT PRIMARY KEY NOT NULL,
phone_thumbnail TEXT NOT NULL,
name TEXT NOT NULL,
custom_name TEXT NOT NULL,
from_device_id TEXT NOT NULL
);
CREATE TABLE message (
contact_phone_number TEXT NOT NULL,
message TEXT NOT NULL,
from_device_id TEXT NOT NULL,
date_received DATETIME CURRENT_TIMESTAMP,
`from` INTEGER DEFAULT 1,
from_type INTEGER DEFAULT 1,
FOREIGN KEY(contact_phone_number) REFERENCES contact(phone_number)
);
CREATE INDEX idx_message_cpm_m ON message(contact_phone_number,message);
CREATE INDEX idx_message_cpm ON message(contact_phone_number);
""";
return _exec_query (query);
}
public override void init_store () {
debug ("Sqlite initialization.");
string db_file = Path.build_filename(Config.create_if_not_exists_config_dir (), "sms-history.db");
int error_code = Database.open (db_file, out _db);
if (error_code != Sqlite.OK) {
warning ("Can't open database: %d: %s\n", _db.errcode (), _db.errmsg ());
is_initialized = false;
}
}
public override void refresh_contact_list () {
if (main_settings.get_boolean ("kdeconnect-telephony-db-setup-done") == true) {
_exec_query ("SELECT * FROM contact;", _refresh_contact_list_callback);
}
}
public override Gee.ArrayList<SMS> get_latest_sms_message (SMSContact sms_contact) {
var sms_list = new Gee.ArrayList<SMS> ();
string query = "SELECT * FROM (";
query += "SELECT * FROM message WHERE contact_phone_number = '" + sms_contact.phone_number + "' ";
query += "ORDER BY date_received DESC LIMIT 20) ";
query += "ORDER BY date_received ASC;";
debug ("SQL: %s", query);
_exec_query (query, (num_columns, values, column_names) => {
SMS sms = new SMS (
values[COL_MESSAGE_TEXT],
int.parse(values[COL_MESSAGE_FROM]),
int.parse(values[COL_MESSAGE_FROM_TYPE]),
new DateTime.from_iso8601 (values[COL_MESSAGE_DATE_RECEIVED], new TimeZone.utc ()));
sms_list.add (sms);
return 0;
});
return sms_list;
}
public override Gee.ArrayList<SMS> get_previous_sms_message (SMSContact sms_contact, DateTime before_date_time) {
var sms_list = new Gee.ArrayList<SMS> ();
string query = "SELECT * FROM message WHERE contact_phone_number = '" + sms_contact.phone_number + "' ";
query += "AND date_received < '" + before_date_time.to_string () + "' ";
query += "ORDER BY date_received DESC LIMIT 10;";
debug ("SQL: %s", query);
_exec_query (query, (num_columns, values, column_names) => {
SMS sms = new SMS (
values[COL_MESSAGE_TEXT],
int.parse(values[COL_MESSAGE_FROM]),
int.parse(values[COL_MESSAGE_FROM_TYPE]),
new DateTime.from_iso8601 (values[COL_MESSAGE_DATE_RECEIVED], new TimeZone.utc ()));
sms_list.add (sms);
return 0;
});
return sms_list;
}
public override void handle_missed_sms (Device device, SMS sms, string contact_name) {
int tot = 0;
string query = "SELECT COUNT(*) AS tot FROM contact WHERE lower(name) = lower('" + _res (contact_name) + "') LIMIT 1";
debug ("SQL: %s", query);
_exec_query (query, (num_columns, values, column_names) => {
tot = values[0].to_int ();
return 0;
});
if (tot == 0) {
debug ("Unable to find a contact.");
return;
}
query = "SELECT * FROM contact WHERE lower(name) = lower('" + _res (contact_name) + "') LIMIT 1";
debug ("SQL: %s", query);
_exec_query (query, (num_columns, values, column_names) => {
SMSContact sms_contact = new SMSContact (
values[COL_CONTACT_PHONE], values[COL_CONTACT_NAME],
values[COL_CONTACT_DEVICE_ID], values[COL_CONTACT_THUMBNAIL],
values[COL_CONTACT_CUSTOM_NAME]);
add_sms (device, sms, sms_contact);
return 0;
});
}
public override void merge_contact (Contact contact) {
foreach (var entry in sms_contact_map.entries) {
SMSContact sms_contact = (SMSContact)entry.value;
if (sms_contact.phone_number == contact.international_phone_number) {
debug ("Updating SMSContact detail for %s", sms_contact.phone_number);
debug ("\tname : %s", contact.name);
debug ("\tphoto_uri: %s", contact.photo_uri);
sms_contact_map.@get (sms_contact.phone_number).contact_image_path =
contact.photo_uri.length > 1 ? File.new_for_uri (contact.photo_uri).get_path () : "";
sms_contact_map.@get (sms_contact.phone_number).custom_name = contact.name;
contact_updated (sms_contact_map.@get (sms_contact.phone_number));
}
}
}
/**
* Real escape string - sort of.
*/
private string _res (string string_to_clean) {
return string_to_clean.replace ("'", "''").replace ("\"", "\\\"");
}
private bool _exec_query (string query, Sqlite.Callback? call_back_function = null) {
_error_code = _db.exec (query, call_back_function, out _error_msg);
if (_error_code != Sqlite.OK) {
warning ("Error: %s", _error_msg);
warning ("Query: %s", query);
return false;
}
return true;
}
private int _refresh_contact_list_callback (int num_columns, string[] values, string[] column_names) {
debug ("Contact: %s | %s | %s",
values[COL_CONTACT_PHONE], values[COL_CONTACT_NAME], values[COL_CONTACT_DEVICE_ID]);
sms_contact_map.@set (
values[COL_CONTACT_PHONE],
new SMSContact (values[COL_CONTACT_PHONE], values[COL_CONTACT_NAME],
values[COL_CONTACT_DEVICE_ID], values[COL_CONTACT_THUMBNAIL],
values[COL_CONTACT_CUSTOM_NAME]));
sms_contact_map.@get (values[COL_CONTACT_PHONE]).set_contact_image ();
contacts_updated (sms_contact_map);
return 0;
}
}
}
/**
* 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;
using Sqlite;
namespace EOSConnect.Plugin {
public class SMSStoreTemp : SMSStoreInterface {
public override void add_sms (Device device, SMS sms, SMSContact sms_contact) {
debug ("Adding SMS in Temp.");
}
}
}
/**
* 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 EOSConnect.Plugin.Popover;
using EOSConnect.Plugin.Dialogs;
using EOSConnect.Widgets;
using Gee;
using MConnect;
namespace EOSConnect.Plugin {
public class Share : PluginInterface {
private ShareSettings share_settings_popover;
construct {
name = _("Share");
icon_name = "emblem-shared";
capability_name = ShareHandler.SHARE_PKT;
description = _("Share files trough devices.");
settings_key_is_active = "kdeconnect-share-active";
show_configure_button = true;
}
public override void handle_configure_button (Device device) {
if (share_settings_popover == null) {
var share_settings_popover = new ShareSettings (device, row_configure_button);
share_settings_popover.show_all ();
share_settings_popover.destroy.connect (() => {
share_settings_popover = null;
});
}
}
public void send_files (Device device) {
Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog (
"Select your favorite file", parent_window, Gtk.FileChooserAction.OPEN,
"_Cancel", Gtk.ResponseType.CANCEL,
"_Open", Gtk.ResponseType.ACCEPT);
chooser.select_multiple = true;
if (chooser.run () == Gtk.ResponseType.ACCEPT) {
SList<string> uris = chooser.get_uris ();
ShareFileInfoProgress file_info_progress = new ShareFileInfoProgress (uris, parent_window);
file_info_progress.show_all ();
int current_file_num = 0;
foreach (unowned string uri in uris) {
try {
UploadTransfer upload_transfer;
((ShareHandler)device.get_path_capability_handler (ShareHandler.SHARE))
.share_file (device, uri, ++current_file_num, out upload_transfer);
// TOCHECK - potential memory leak here ?
upload_transfer.progress.connect ((progress_percentage, file_num, file_uri) => {
file_info_progress.update_progress (--file_num, progress_percentage);
});
} catch (Error e) {
file_info_progress.destroy ();
warning ("Error: %s", e.message);
}
}
}
chooser.close ();
}
}
}
/**
* 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 EOSConnect;
using EOSConnect.Widgets;
using EOSConnect.Plugin;
using EOSConnect.Plugin.Popover;
using MConnect;
namespace EOSConnect.Plugin {
public class Telephony : PluginInterface {
private TelephonySettings _telephony_settings_popover;
construct {
name = _("Telephony");
icon_name = "phone";
capability_name = TelephonyHandler.TELEPHONY;
description = _("Calls notification and SMS.");
settings_key_is_active = "kdeconnect-telephony-active";
show_configure_button = true;
}
public override PluginListBoxRow get_plugin_list_box_row (PluginInterface plugin, Device device) {
return new Widgets.TelephonyPluginListBoxRow (plugin, device);
}
public override void handle_configure_button (Device device) {
if (_telephony_settings_popover == null) {
var _telephony_settings_popover = new TelephonySettings (device, row_configure_button);
_telephony_settings_popover.show_all ();
_telephony_settings_popover.destroy.connect (() => {
_telephony_settings_popover = null;
});
}
}
}
}
/**
* 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 EOSConnect;
using EOSConnect.Plugin;
using EOSConnect.Plugin.Widgets;
using Gee;
using MConnect;
namespace EOSConnect.Plugin.Views {
public class SMSMessagesView : Gtk.Grid {
public HashMap<string, Device> devices_map { get; construct; }
public SMSContact sms_contact { get; construct; }
public Widgets.SMSContactListBox device_list_box { get; construct; }
private SMSTextEntry text_entry;
private DateTime first_message_date_time_utc;
private Gtk.ScrolledWindow scrolled_window ;
private Gtk.TextIter text_iter;
private Gtk.TextBuffer text_message_buffer;
private Gtk.TextView text_view;
private Gtk.TextMark text_mark_auto_scroll;
private int last_message_day = 0;
public SMSMessagesView (
SMSContact sms_contact,
Widgets.SMSContactListBox device_list_box,
HashMap<string, Device> devices_map
) {
Object (
sms_contact: sms_contact,
device_list_box: device_list_box,
devices_map: devices_map
);
}
construct {
orientation = Gtk.Orientation.VERTICAL;
scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window.expand = true;
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
Gtk.TextTag text_tag_day = new Gtk.TextTag ("day");
text_tag_day.scale = Pango.Scale.SMALL;
text_tag_day.justification = Gtk.Justification.CENTER;
text_tag_day.pixels_below_lines = 10;
text_tag_day.pixels_above_lines = 10;
text_tag_day.foreground = "black";
Gtk.TextTag text_tag_msg = new Gtk.TextTag ("msg");
text_tag_msg.foreground = "black";
text_tag_msg.justification = Gtk.Justification.LEFT;
Gtk.TextTag text_tag_my_msg = new Gtk.TextTag ("my-msg");
text_tag_my_msg.foreground = "black";
text_tag_my_msg.left_margin = 150;
text_tag_my_msg.justification = Gtk.Justification.LEFT;
Gtk.TextTag text_tag_time_msg = new Gtk.TextTag ("time-msg");
text_tag_time_msg.justification = Gtk.Justification.LEFT;
text_tag_time_msg.foreground = "red";
Gtk.TextTag text_tag_my_time_msg = new Gtk.TextTag ("my-time-msg");
text_tag_my_time_msg.left_margin = 150;
text_tag_my_time_msg.foreground = "blue";
text_tag_my_time_msg.justification = Gtk.Justification.LEFT;
Gtk.TextTagTable text_tag_table = new Gtk.TextTagTable ();
text_tag_table.add (text_tag_day);
text_tag_table.add (text_tag_my_msg);
text_tag_table.add (text_tag_msg);
text_tag_table.add (text_tag_time_msg);
text_tag_table.add (text_tag_my_time_msg);
text_mark_auto_scroll = new Gtk.TextMark ("auto-scroll");
text_message_buffer = new Gtk.TextBuffer (text_tag_table);
text_message_buffer.get_iter_at_offset (out text_iter, 0);
text_message_buffer.add_mark (text_mark_auto_scroll, text_iter);
text_view = new Gtk.TextView ();
text_view.set_wrap_mode (Gtk.WrapMode.WORD);
text_view.editable = false;
text_view.cursor_visible = false;
text_view.buffer = text_message_buffer;
text_view.top_margin = 5;
text_view.bottom_margin = 5;
text_view.left_margin = 5;
text_view.right_margin = 5;
int i = 0;
foreach (SMS sms in SMSStore.instance ().get_latest_sms_message (sms_contact)) {
if (i++ == 0) {
first_message_date_time_utc = sms.date_time;
}
add_message_in_textview (sms);
}
scrolled_window.add (text_view);
text_entry = new SMSTextEntry (devices_map);
text_entry.message_to_send.connect ((message, device) => { send_message (message, device); });
add (scrolled_window);
add (text_entry);
show_all ();
scrolled_window.edge_overshot.connect ((pos) => {
if( pos == Gtk.PositionType.TOP ) {
foreach (SMS sms in SMSStore.instance ().get_previous_sms_message (sms_contact, first_message_date_time_utc)) {
first_message_date_time_utc = sms.date_time;
text_message_buffer.get_iter_at_line (out text_iter, 0);
add_message_in_textview (sms, true);
}
text_message_buffer.get_iter_at_line (out text_iter, text_message_buffer.get_line_count ());
}
}) ;
}
public void update_ui_adding_sms (SMS sms) {
add_message_in_textview (sms);
}
public void update_combo_box_devices () {
text_entry.update_combo_box_devices ();
}
public void add_message_in_textview (SMS sms, bool adding_old_sms = false) {
if (last_message_day != sms.date_time.get_day_of_week ()) {
string msg_datetime_format = "------------ " + sms.date_time.format ("%A %e %B %Y") + " ------------";
text_message_buffer.insert_with_tags_by_name (ref text_iter, msg_datetime_format, msg_datetime_format.length, "day");
text_message_buffer.insert(ref text_iter, "\n", 1);
last_message_day = sms.date_time.get_day_of_week ();
}
string time_message = sms.date_time.format ("%H:%M - ");
if (sms.from == SMS.FROM_CONTACT) {
text_message_buffer.insert_with_tags_by_name(ref text_iter, time_message, time_message.length, "time-msg");
text_message_buffer.insert_with_tags_by_name(ref text_iter, sms.message, sms.message.length, "msg");
} else {
text_message_buffer.insert_with_tags_by_name(ref text_iter, time_message, time_message.length, "my-time-msg");
text_message_buffer.insert_with_tags_by_name (ref text_iter, sms.message, sms.message.length, "my-msg");
}
text_message_buffer.insert(ref text_iter, "\n\n", 2);
if(adding_old_sms == false) {
text_view.scroll_to_mark (text_mark_auto_scroll, 0, true, 0, 0);
}
}
private void send_message (string message, Device device) {
SMS sms = new SMS (
message,
SMS.FROM_ME,
SMS.FROM_TYPE_EOSCONNECT,
new DateTime.now_utc ());
if (device.has_capability_handler (TelephonyHandler.TELEPHONY) ) {
((TelephonyHandler)device.get_path_capability_handler(TelephonyHandler.TELEPHONY))
.send_sms (device, sms_contact.phone_number, message);
SMSStore.instance ().add_sms (device, sms, sms_contact);
}
}
}
}
/**
* 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 EOSConnect.Widgets;
using MConnect;
namespace EOSConnect.Plugin.Widgets {
public class BatteryPluginListBoxRow : PluginListBoxRow {
public BatteryPluginListBoxRow (
PluginInterface plugin_interface,
Device device
) {
Object (
plugin_interface: plugin_interface,
device: device
);
}
public override void update_ui () {
row_grid.attach (row_image, 0, 0, 1, 2);
row_grid.attach (row_name, 1, 0, 1, 1);
row_grid.attach (row_description, 1, 1, 1, 1);
row_grid.attach (row_configure_button, 2, 0, 1, 2);
row_grid.attach (row_switch, 3, 0, 1, 2);
add (row_grid);
row_switch.notify["active"].connect (() => {
((BatteryHandler)device.get_path_capability_handler (BatteryHandler.BATTERY)).battery_update ();
row_configure_button.sensitive = row_switch.active;
row_description.sensitive = row_switch.active;
row_name.sensitive = row_switch.active;
row_image.sensitive = row_switch.active;
});
}
}
}
/**
* 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 EOSConnect.Widgets;
using MConnect;
namespace EOSConnect.Plugin.Widgets {
public class PingPluginListBoxRow : PluginListBoxRow {
public PingPluginListBoxRow (
PluginInterface plugin_interface,
Device device
) {
Object (
plugin_interface: plugin_interface,
device: device
);
}
public override void update_ui () {
var row_ping_button = new Gtk.Button.with_label ("ping");
row_ping_button.valign = Gtk.Align.CENTER;
row_ping_button.sensitive = device.settings.get_boolean (plugin_interface.settings_key_is_active);
row_grid.attach (row_image, 0, 0, 1, 2);
row_grid.attach (row_name, 1, 0, 1, 1);
row_grid.attach (row_description, 1, 1, 1, 1);
row_grid.attach (row_ping_button, 2, 0, 1, 2);
row_grid.attach (row_switch, 3, 0, 1, 2);
add (row_grid);
row_ping_button.clicked.connect(() => {
if (device.has_capability_handler (PingHandler.PING)) {
((PingHandler)device.get_path_capability_handler(PingHandler.PING)).send_ping (device);
}
});
row_switch.notify["active"].connect (() => {
row_ping_button.sensitive = row_switch.active;
row_configure_button.sensitive = row_switch.active;
row_description.sensitive = row_switch.active;
row_name.sensitive = row_switch.active;
row_image.sensitive = row_switch.active;
});
}
}
}
/**
* 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 EOSConnect;
using MConnect;
namespace EOSConnect.Plugin.Widgets {
public class SMSContactListBox : Gtk.ListBox {
private Gtk.Label _contacts_label;
construct {
selection_mode = Gtk.SelectionMode.SINGLE;
set_header_func (update_headers);
_contacts_label = new Gtk.Label (_("Contacts"));
_contacts_label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);
_contacts_label.halign = Gtk.Align.START;
show_all ();
}
public void update_selected_list_box_row () {
var list_box_row = (SMSContactListBoxRow)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 (_contacts_label);
}
}
}
}
/**
* 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 EOSConnect;
using EOSConnect.Plugin;
using MConnect;
namespace EOSConnect.Plugin.Widgets {
public class SMSContactListBoxRow : Gtk.ListBoxRow {
public weak SMSContact sms_contact { get; construct; }
private Gtk.Label contact_name_label;
private Granite.Widgets.Avatar avatar;
public SMSContactListBoxRow (SMSContact sms_contact) {
Object (
sms_contact: sms_contact
);
}
construct {
var grid = new Gtk.Grid ();
grid.margin = 6;
grid.column_spacing = 6;
avatar = new Granite.Widgets.Avatar ();
setup_avatar ();
contact_name_label = new Gtk.Label (sms_contact.custom_name);
contact_name_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
contact_name_label.ellipsize = Pango.EllipsizeMode.END;
contact_name_label.halign = Gtk.Align.START;
contact_name_label.valign = Gtk.Align.START;
var contact_phone_number = new Gtk.Label (sms_contact.phone_number);
contact_phone_number.margin_top = 2;
contact_phone_number.use_markup = true;
contact_phone_number.ellipsize = Pango.EllipsizeMode.END;
contact_phone_number.halign = Gtk.Align.START;
contact_phone_number.valign = Gtk.Align.START;
var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
box.pack_start (contact_phone_number, false, false, 0);
grid.attach (avatar, 0, 0, 1, 2);
grid.attach (contact_name_label, 1, 0, 1, 1);
grid.attach (box, 1, 1, 1, 1);
add (grid);
}
public void update_ui () {
setup_avatar ();
contact_name_label.label = sms_contact.custom_name;
}
private void setup_avatar () {
if (sms_contact.contact_image_path.length > 10) {
try {
var size = 32 * get_style_context ().get_scale ();
var avatar_pixbuf = new Gdk.Pixbuf.from_file_at_scale (sms_contact.contact_image_path, size, size, false);
avatar.pixbuf = avatar_pixbuf;
} catch (Error e) {
warning ("Error: %s", e.message);
avatar.show_default (32);
}
} else {
avatar.show_default (32);
}
}
}
}
/**
* 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 EOSConnect;
using EOSConnect.Plugin;
using Gee;
using MConnect;
namespace EOSConnect.Plugin.Widgets {
public class SMSTextEntry : Gtk.Box {
public signal void message_to_send (string text, Device device);
public HashMap<string, Device> devices_map { get; construct; }
private Gtk.ComboBoxText combo_box_devices;
public Gtk.TextView entrytext_view { get; private set; }
public SMSTextEntry (HashMap<string, Device> devices_map) {
Object (
devices_map: devices_map
);
}
construct {
combo_box_devices = new Gtk.ComboBoxText ();
combo_box_devices.margin = 5 ;
combo_box_devices.valign = Gtk.Align.START ;
entrytext_view = new Gtk.TextView ();
entrytext_view.border_width = 1;
entrytext_view.height_request = 50;
entrytext_view.hexpand = true;
entrytext_view.monospace = true;
entrytext_view.key_press_event.connect ((event_key) => {handle_key_pressed (event_key);});
var send_message_button = new Gtk.Button.with_label (_("Send message"));
send_message_button.margin = 5;
send_message_button.clicked.connect (handle_button_clicked);
var input_grid = new Gtk.Grid ();
// left, top, width = 1, height = 1
input_grid.attach (entrytext_view, 0, 0, 2, 1);
input_grid.attach (combo_box_devices, 0, 6, 1, 1);
input_grid.attach (send_message_button, 1, 6, 1, 1);
add (input_grid);
}
public void update_combo_box_devices () {
combo_box_devices.remove_all ();
bool active_setup = false;
foreach (var entry in devices_map.entries) {
if (entry.value.is_paired == true && entry.value.is_active == true &&
entry.value.has_capability_handler (TelephonyHandler.TELEPHONY) == true &&
entry.value.is_capabality_activated (TelephonyHandler.TELEPHONY) == true) {
combo_box_devices.append (entry.value.to_unique_string (), entry.value.custom_name);
if (active_setup == false) {
active_setup = true;
combo_box_devices.set_active_id (entry.value.to_unique_string ());
}
}
}
}
private void handle_button_clicked () {
send_signal ();
}
private bool handle_key_pressed (Gdk.EventKey event_key) {
if (Gdk.ModifierType.SHIFT_MASK in event_key.state && event_key.keyval == 65293) {
send_signal ();
return true;
}
return false;
}
private void send_signal () {
Device device = devices_map.@get (combo_box_devices.get_active_id ());
message_to_send (entrytext_view.buffer.text, device);
entrytext_view.buffer.text = "";
}
}
}
/**
* 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 EOSConnect.Widgets;
using MConnect;
namespace EOSConnect.Plugin.Widgets {
public class TelephonyPluginListBoxRow : PluginListBoxRow {
public TelephonyPluginListBoxRow (
PluginInterface plugin_interface,
Device device
) {
Object (
plugin_interface: plugin_interface,
device: device
);
}
public override void update_ui () {
row_grid.attach (row_image, 0, 0, 1, 2);
row_grid.attach (row_name, 1, 0, 1, 1);
row_grid.attach (row_description, 1, 1, 1, 1);
row_grid.attach (row_configure_button, 2, 0, 1, 2);
row_grid.attach (row_switch, 3, 0, 1, 2);
add (row_grid);
row_switch.notify["active"].connect (() => {
((TelephonyHandler)device.get_path_capability_handler (TelephonyHandler.TELEPHONY)).telephony_update ();
row_configure_button.sensitive = row_switch.active;
row_description.sensitive = row_switch.active;
row_name.sensitive = row_switch.active;
row_image.sensitive = row_switch.active;
});
}
}
}
/**
* 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 EOSConnect;
using EOSConnect.Plugin;
using EOSConnect.Plugin.Views;
using MConnect;
namespace EOSConnect.Plugin.Windows {
public class SMSHistory : Gtk.Stack {
public GLib.Settings main_settings { get; construct; }
public HashMap<string, Device> devices_map { get; construct; }
public ContactsInterface contacts_interface;
private Popover.SMSNewMessageNewContact popover_new_sms;
private Widgets.SMSContactListBox sms_contact_list_box;
private Gtk.Stack stack;
private string latest_contact_selected = null;
public SMSHistory (GLib.Settings main_settings, HashMap<string, Device> devices_map) {
Object (
main_settings: main_settings,
devices_map: devices_map
);
// set_size_request (800, 700);
// set_default_size (600, 600);
}
construct {
// title = "SMS";
// var new_sms_button = new Gtk.Button.from_icon_name ("mail-message-new");
// new_sms_button.tooltip_text = _("Send a new SMS");
// new_sms_button.valign = Gtk.Align.CENTER;
// var headerbar = new Gtk.HeaderBar ();
// headerbar.get_style_context ().add_class ("default-decoration");
// headerbar.show_close_button = true;
// headerbar.pack_start (new_sms_button);
// headerbar.title = "SMS";
// set_titlebar (headerbar);
// window_position = Gtk.WindowPosition.CENTER;
var scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window.expand = true;
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
sms_contact_list_box = new Widgets.SMSContactListBox ();
sms_contact_list_box.width_request = 180;
scrolled_window.add (sms_contact_list_box);
var sidebar_grid = new Gtk.Grid ();
sidebar_grid.orientation = Gtk.Orientation.VERTICAL;
sidebar_grid.add (scrolled_window);
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);
add (paned);
sms_contact_list_box.row_selected.connect (sms_contact_list_box_selected);
sms_contact_list_box.show_all ();
scrolled_window.show_all ();
// show_all ();
}
public void update_list_box_ui (SMSContact sms_contact) {
int count = 0;
sms_contact_list_box.@foreach (() => {
Widgets.SMSContactListBoxRow sms_contact_list_box_row = (Widgets.SMSContactListBoxRow)sms_contact_list_box.get_row_at_index (count);
if (sms_contact_list_box_row.sms_contact.phone_number == sms_contact.phone_number) {
sms_contact_list_box_row.update_ui ();
}
count++;
});
}
public void update_ui (HashMap<string, SMSContact> sms_contact_map) {
foreach (var entry in sms_contact_map.entries) {
add_sms_history_message_view (entry.value);
bool contact_already_in_list_box = false;
int count = 0;
sms_contact_list_box.@foreach (() => {
Widgets.SMSContactListBoxRow sms_contact_list_box_row = (Widgets.SMSContactListBoxRow)sms_contact_list_box.get_row_at_index (count);
if (sms_contact_list_box_row.sms_contact.phone_number == entry.value.phone_number) {
contact_already_in_list_box = true;
((SMSMessagesView)stack.get_child_by_name (entry.value.phone_number)).update_combo_box_devices ();
}
count++;
});
if (contact_already_in_list_box == false) {
sms_contact_list_box.insert (new Widgets.SMSContactListBoxRow (entry.value), count);
}
}
// First time we populate the list box.
if (sms_contact_list_box.get_selected_row () == null && latest_contact_selected == null) {
sms_contact_list_box.select_row (sms_contact_list_box.get_row_at_index (0));
latest_contact_selected = ((Widgets.SMSContactListBoxRow)sms_contact_list_box.get_row_at_index (0)).sms_contact.phone_number;
}
}
public void update_message_ui_adding_sms (SMS sms) {
if (sms.sms_contact != null) {
((SMSMessagesView)stack.get_child_by_name (sms.sms_contact.phone_number)).add_message_in_textview (sms);
}
update_available_device_combobox ();
}
public void update_available_device_combobox () {
stack.get_children ().foreach ((entry) => {
SMSMessagesView sms_view = (SMSMessagesView)entry;
sms_view.update_combo_box_devices ();
});
}
public void open_sms_tab (Device device) {
show_all ();
// present ();
}
public void open_sms_window_reply () {
print ("\n\nopen_sms_window_reply ()\n\n");
show_all ();
// present ();
}
private void add_sms_history_message_view (SMSContact sms_contact) {
if (stack.get_child_by_name (sms_contact.phone_number) == null) {
debug ("Adding SMSMessagesView Widget for contact '%s'".printf (sms_contact.contact_name));
SMSMessagesView sms_message_view = new SMSMessagesView (sms_contact, sms_contact_list_box, devices_map);
sms_message_view.update_combo_box_devices ();
stack.add_named (sms_message_view, sms_contact.phone_number);
}
}
private void sms_contact_list_box_selected (Gtk.ListBoxRow? sms_contact_item) {
SMSContact? sms_contact = null;
if (sms_contact_item != null) {
sms_contact = ((Widgets.SMSContactListBoxRow)sms_contact_item).sms_contact;
latest_contact_selected = sms_contact.phone_number;
stack.set_visible_child_name (sms_contact.phone_number);
}
}
public void handle_new_sms_button (Gtk.Button new_sms_button) {
if (popover_new_sms == null) {
var popover_new_sms = new Popover.SMSNewMessageNewContact (new_sms_button, contacts_interface, devices_map);
popover_new_sms.update_combo_box_devices ();
popover_new_sms.show_all ();
popover_new_sms.destroy.connect (() => {
popover_new_sms = null;
});
}
}
}
}
/**
* 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 {
public class Tools {
public static string get_icon_name(string device_type) {
string icon_name = device_type;
if (device_type == "tablet") {
icon_name = "computer-apple-ipad";
}
return icon_name;
}
public static string get_status_icon_name (Device device) {
string status_icon_name = "user-offline";
if (device.is_paired == true && device.is_active == true)
status_icon_name = "user-available";
else if (device.is_paired == true && device.is_active == false)
status_icon_name = "user-away";
return status_icon_name;
}
public static string get_status_text (Device device) {
string status_text = _("Not paired");
if (device.is_paired == true && device.is_active == true)
status_text = _("Connected");
else if (device.is_paired == true && device.is_active == false)
status_text = _("Not connected");
else if (device.is_paired == false && device.is_active == false)
status_text = _("Not paired and not connected");
return status_text;
}
public static string get_battery_icon_name (Device device) {
string battery_icon_name = "battery";
if (device.battery_level == 100 && device.battery_charging == true) {
battery_icon_name = "battery-full-charged";
} else if (device.battery_level >= 99) {
battery_icon_name = (device.battery_charging == true) ? "battery-full-charging" : "battery-full";
} else if (device.battery_level >= 60 && device.battery_level < 99) {
battery_icon_name = (device.battery_charging == true) ? "battery-good-charging" : "battery-good";
} else if (device.battery_level >= 10 && device.battery_level < 60) {
battery_icon_name = (device.battery_charging == true) ? "battery-low-charging" : "battery-low";
} else if (device.battery_level >= 2 && device.battery_level < 10) {
battery_icon_name = (device.battery_charging == true) ? "battery-caution-charging" : "battery-caution";
} else {
battery_icon_name = (device.battery_charging == true) ? "battery-empty-charging" : "battery-empty";
}
return battery_icon_name;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment