Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] network applet: Add settings for wireless network list. #10076

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const NM80211Mode = NM['80211Mode'];
const NM80211ApFlags = NM['80211ApFlags'];
const NM80211ApSecurityFlags = NM['80211ApSecurityFlags'];

// number of wireless networks that should be visible
// (the remaining are placed into More...)
const NUM_VISIBLE_NETWORKS = 5;
const APPLET_SETTINGS = {
num_visible_networks: 5,
hide_other_networks_when_connected: false
};

var NMIface = '\
<node> \
Expand Down Expand Up @@ -595,6 +596,8 @@ NMDevice.prototype = {
if (this._activeConnection) {
this._createActiveConnectionItem();
this.section.addMenuItem(this._activeConnectionItem);
if (APPLET_SETTINGS.hide_other_networks_when_connected)
return;
}
if (this._connections.length > 0) {
let activeOffset = this._activeConnectionItem ? 1 : 0;
Expand All @@ -606,7 +609,7 @@ NMDevice.prototype = {
continue;
obj.item = this._createConnectionItem(obj);

if (j + activeOffset >= NUM_VISIBLE_NETWORKS) {
if (j + activeOffset >= APPLET_SETTINGS.num_visible_networks) {
if (!this._overflowItem) {
this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More"));
this.section.addMenuItem(this._overflowItem);
Expand Down Expand Up @@ -1384,7 +1387,7 @@ NMDeviceWireless.prototype = {
// clear the cycle, and allow the construction of the new item
item._apObj.item = null;

this._createNetworkItem(item._apObj, NUM_VISIBLE_NETWORKS-1);
this._createNetworkItem(item._apObj, APPLET_SETTINGS.num_visible_networks-1);
} else {
log('The more... menu was existing and empty! This should not happen');
}
Expand Down Expand Up @@ -1616,15 +1619,18 @@ NMDeviceWireless.prototype = {
}
apObj.item._apObj = apObj;

if (position < NUM_VISIBLE_NETWORKS) {
if (this._activeConnectionItem && APPLET_SETTINGS.hide_other_networks_when_connected)
return;

if (position < APPLET_SETTINGS.num_visible_networks) {
apObj.isMore = false;
this.section.addMenuItem(apObj.item, position);
} else {
if (!this._overflowItem) {
this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More"));
this.section.addMenuItem(this._overflowItem);
}
this._overflowItem.menu.addMenuItem(apObj.item, position - NUM_VISIBLE_NETWORKS);
this._overflowItem.menu.addMenuItem(apObj.item, position - APPLET_SETTINGS.num_visible_networks);
apObj.isMore = true;
}
},
Expand All @@ -1636,6 +1642,8 @@ NMDeviceWireless.prototype = {
if(this._activeConnection) {
this._createActiveConnectionItem();
this.section.addMenuItem(this._activeConnectionItem);
if (APPLET_SETTINGS.hide_other_networks_when_connected)
return;
}

let activeOffset = this._activeConnectionItem ? 1 : 0;
Expand Down Expand Up @@ -1692,7 +1700,11 @@ CinnamonNetworkApplet.prototype = {

this.settings = new Settings.AppletSettings(this, metadata.uuid, this.instance_id);
this.settings.bind("keyOpen", "keyOpen", this._setKeybinding);
this.settings.bind("num-visible-networks", this._setNumVisibleNetworks);
this.settings.bind("hide-other-networks-when-connected", this._setHideOtherNetworksWhenConnected);
this._setKeybinding();
this._setNumVisibleNetworks();
this._setHideOtherNetworksWhenConnected();

NM.Client.new_async(null, Lang.bind(this, this._clientGot));
}
Expand All @@ -1705,6 +1717,15 @@ CinnamonNetworkApplet.prototype = {
Main.keybindingManager.addHotKey("network-open-" + this.instance_id, this.keyOpen, Lang.bind(this, this._openMenu));
},

_setNumVisibleNetworks() {
APPLET_SETTINGS.num_visible_networks = this.num_visible_networks;
},

_setHideOtherNetworksWhenConnected() {
APPLET_SETTINGS.hide_other_networks_when_connected = this.hide_other_networks_when_connected;
},


_clientGot: function(obj, result) {
try {
this._client = NM.Client.new_finish(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@
"description": "Show menu",
"default": "<Shift><Super>n",
"tooltip": "Set keybinding(s) to show the network applet menu."
},
"num-visible-networks": {
"type" : "spinbutton",
"default" : 5,
"min" : 1,
"max" : 10,
"step" : 1,
"description" : "Wireless networks listed in panel",
"tooltip" : "Choose how many wireless networks are shown in panel. Additional networks are listed in More menu"
},
"hide-other-networks-when-connected": {
"type" : "switch",
"default" : false,
"description" : "Hide other wireless networks when connected",
"tooltip" : "When enabled and connected to a wireless network, other networks are not listed."
}
}