Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
* extension.js: strip Shell sms widget, cleanup and reorder some funcs
* lib.js: remove old log function
* sms.js: minor changes here and there
  • Loading branch information
andyholmes committed Jul 29, 2017
1 parent 3487600 commit f537aa8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 125 deletions.
120 changes: 17 additions & 103 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,70 +38,6 @@ const DeviceVisibility = {

/** Composite Widgets */

/** MessageWidget */
const SMSWidget = new Lang.Class({
Name: "SMSWidget",
Extends: PopupMenu.PopupMenuSection,

_init: function (device) {
this.parent();

this.titleBar = new PopupMenu.PopupBaseMenuItem({
reactive: false,
can_focus: false
});
this.addMenuItem(this.titleBar, { expand: true });

this.closeButton = new St.Button({
child: new St.Icon({
icon_name: "go-previous-symbolic",
icon_size: 16
})
});
this.titleBar.actor.add(this.closeButton);

this.label = new St.Label({
text: _("New Message"),
x_expand: true,
x_align: Clutter.ActorAlign.CENTER
});
this.titleBar.actor.add(this.label);

this.detachButton = new St.Button({
child: new St.Icon({
icon_name: "detach-symbolic",
icon_size: 16
})
});
this.titleBar.actor.add(this.detachButton);

// Phone Number/Contact Entry
this.contactEntry = new St.Entry({
input_purpose: Gtk.InputPurpose.NUMBER,
hint_text: _("Phone number...")
});
this.actor.add(this.contactEntry, { expand: true });

// Message View
this.messageView = new St.Label({
text: "Test",
style: "padding: 2em 1em;",
style_class: "popup-sub-menu"
});
this.actor.add(this.messageView, { expand: true });

// Message Entry
this.messageEntry = new St.Entry();
this.messageEntry.set_secondary_icon(
new St.Icon({
icon_name: "mail-reply-sender-symbolic",
icon_size: 16
})
);
this.actor.add(this.messageEntry, { expand: true });
}
});

// A PopupMenu used as an information and control center for a device,
// accessible either as a User Menu submenu or Indicator popup-menu.
const DeviceMenu = new Lang.Class({
Expand Down Expand Up @@ -178,10 +114,7 @@ const DeviceMenu = new Lang.Class({

this.smsButton = this._addActionButton(
"user-available-symbolic",
() => {
this.smsItem.actor.visible = true;
this.actionBar.actor.visible = false;
}
Lang.bind(this, this._smsAction)
);
this.findButton = this._addActionButton(
"find-location-symbolic",
Expand All @@ -195,38 +128,16 @@ const DeviceMenu = new Lang.Class({
"send-to-symbolic",
Lang.bind(this, this._shareAction)
);

// SMS section
this.smsItem = new SMSWidget(device);
this.smsItem.actor.visible = false;
// SMS Section -> Detach Button "clicked" (launch Gtk SMS App)
this.smsItem.detachButton.connect("clicked", () => {
GLib.spawn_command_line_async(
"gjs " + Me.path + "/sms.js \"" + device.gObjectPath + "\""
);

this.smsItem.actor.visible = false;
this.actionBar.actor.visible = true;
this._getTopMenu().close(true);
});
// SMS Section -> Close "clicked" (shut SMS widget)
this.smsItem.closeButton.connect("clicked", () => {
this.smsItem.actor.visible = false;
this.actionBar.actor.visible = true;
});
this.addMenuItem(this.smsItem);
// SMS Section -> Menu closed while SMS Widget open
this._getTopMenu().connect("menu-closed", () => {
this.smsItem.actor.visible = false;
this._stateChanged(this.device);
});

// Property signals
device.connect(
"changed::battery",
Lang.bind(this, this._batteryChanged)
);
device.connect("notify::name", Lang.bind(this, this._nameChanged));
device.connect(
"notify::name",
Lang.bind(this, this._nameChanged)
);
device.connect(
"changed::plugins",
Lang.bind(this, this._pluginsChanged)
Expand Down Expand Up @@ -255,10 +166,8 @@ const DeviceMenu = new Lang.Class({
_addActionButton: function (name, callback) {
let button = new St.Button({ style_class: "system-menu-action" });
button.child = new St.Icon({ icon_name: name });

button.style = "padding: 8px;";

if (callback) { button.connect("clicked", callback); }
button.connect("clicked", callback);

this.actionBar.actor.add(button, { expand: true, x_fill: false });

Expand Down Expand Up @@ -375,8 +284,8 @@ const DeviceMenu = new Lang.Class({

_findAction: function (button) {
debug("extension.DeviceMenu._findAction()");
this.device.ring();
this._getTopMenu().close(true);
this.device.ring();
},

_shareAction: function (button) {
Expand Down Expand Up @@ -406,16 +315,22 @@ const DeviceMenu = new Lang.Class({
},

_smsAction: function (button) {
debug("extension.DeviceMenu._smsAction(): Not Implemented");
debug("extension.DeviceMenu._smsAction()");

this._getTopMenu().close(true);

GLib.spawn_command_line_async(
"gjs " + Me.path + "/sms.js \"" + this.device.gObjectPath + "\""
);
}
});

Signals.addSignalMethods(DeviceMenu.prototype);

// An indicator representing a device in Menu.panel.statusArea, used as an
// optional location for a DeviceMenu.
/**
* An indicator representing a device in Menu.panel.statusArea, used as an
* optional location for a DeviceMenu.
*/
const DeviceIndicator = new Lang.Class({
Name: "DeviceIndicator",
Extends: PanelMenu.Button,
Expand All @@ -436,8 +351,7 @@ const DeviceIndicator = new Lang.Class({
this.menu.addMenuItem(this.deviceMenu);

// Signals
let sets = ["device-indicators", "device-visibility"];
sets.forEach((setting) => {
["device-indicators", "device-visibility"].forEach((setting) => {
Settings.connect("changed::" + setting, () => { this._sync(); });
});

Expand Down
16 changes: 1 addition & 15 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const AboutDialog = new Lang.Class({
website: Me.metadata.url,
//website_label: Me.metadata.name + _(" Website"),

authors: [ "Andy Holmes <[email protected]>" ],
authors: [ "Andy Holmes <[email protected]>" ], // TODO
//artists: Me.metadata.artists,
translator_credits: _("translator-credits"),
copyright: "Copyright 2017 Andy Holmes", // TODO
Expand Down Expand Up @@ -712,26 +712,12 @@ function initTranslations() {
* - log
* - debug
* - assert
*
*/

/**
* Prints a message to the log, prepended with the UUID of the extension
* @param {String} msg - the message
*/

// FIXME: "[@UUID@]: , @LOG_MESSAGE@"
//log = (function (stockLog, msg) {
// stockLog("[" + Me.metadata.uuid + "]: " + msg);
//})(log);
//(function () {
// var old = log;
// log = function () {
// Array.prototype.unshift.call(arguments, "[" + Me.metadata.uuid + "]: ");
// old.apply(this, arguments)
// }
//})();

function log(msg) {
global.log("[" + Me.metadata.uuid + "]: " + msg);
}
Expand Down
11 changes: 4 additions & 7 deletions src/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ function getPath() {
}

imports.searchPath.push(getPath());
const MConnect = imports.mconnect;
const KDEConnect = imports.kdeconnect;
const Convenience = imports.lib;

// infer backend and init Device()
if (ARGV[0].split("/")[2] === "mconnect") {
var DEVICE = new MConnect.Device(ARGV[0]);
var DEVICE = new imports.mconnect.Device(ARGV[0]);
} else {
log("KDE");
var DEVICE = new KDEConnect.Device(ARGV[0]);
var DEVICE = new imports.kdeconnect.Device(ARGV[0]);
}


Expand Down Expand Up @@ -168,7 +166,7 @@ const ContactCompletion = new Lang.Class({
if (!this.service) { throw Error("failed to load Google Contacts"); }

// Retrieve the contacts if there is
// TODO: multi-page/truncated feeds
// TODO: multi-page/truncated feeds?
this.contacts = [];
let query = new GData.Query({ q: "" });
let count = 0;
Expand Down Expand Up @@ -559,8 +557,7 @@ const ApplicationWindow = new Lang.Class({
// Send to each contactNumber
for (let number of contactNumbers) {
log("Sending message to '" + number + "': " + entry.text);
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
//DEVICE.sms(number, entry.text);
DEVICE.sms(number, entry.text);
}

// Log the sent message in the Conversation View and clear the entry
Expand Down

0 comments on commit f537aa8

Please sign in to comment.