First gnome-shell 40.x fixes.

All lower versions are abandoned for the moment (?).
master
Jens Lody 4 years ago
parent c28898dc1e
commit 7a2e0f6c5a
  1. 2
      data/Makefile.am
  2. 2
      data/metadata.json.in
  3. 7
      data/prefs.css
  4. 1083
      data/weather-settings.ui
  5. 4
      gnome-shell-extension-openweather.cbp
  6. 198
      src/prefs.js

@ -7,7 +7,7 @@ uuid = openweather-extension@jenslody.de
extensiondir = $(topextensiondir)/$(uuid) extensiondir = $(topextensiondir)/$(uuid)
dist_extension_DATA = OpenWeather.png stylesheet.css weather-settings.ui dist_extension_DATA = OpenWeather.png stylesheet.css prefs.css weather-settings.ui
nodist_extension_DATA = metadata.json $(EXTRA_EXTENSION) nodist_extension_DATA = metadata.json $(EXTRA_EXTENSION)

@ -2,7 +2,7 @@
"uuid": "@uuid@", "uuid": "@uuid@",
"name": "OpenWeather", "name": "OpenWeather",
"description": "Weather extension to display weather information from https://openweathermap.org/ or https://darksky.net for almost all locations in the world.\nFor openweathermap.org, you can either use the extensions default-key or register at https://openweathermap.org/appid and set the appropriate switch in the preferences dialog to \"off\".\nFor Dark Sky you have to register at https://darksky.net/dev/register and get a personal API-key.\n\nSince version 29 this extensions uses coordinates to store the locations and makes the names editable to support multiple weather-providers!\nIf you update from versions prior to 29 to 29 or greater (with darksky.net - support) you have to recreate your locations.", "description": "Weather extension to display weather information from https://openweathermap.org/ or https://darksky.net for almost all locations in the world.\nFor openweathermap.org, you can either use the extensions default-key or register at https://openweathermap.org/appid and set the appropriate switch in the preferences dialog to \"off\".\nFor Dark Sky you have to register at https://darksky.net/dev/register and get a personal API-key.\n\nSince version 29 this extensions uses coordinates to store the locations and makes the names editable to support multiple weather-providers!\nIf you update from versions prior to 29 to 29 or greater (with darksky.net - support) you have to recreate your locations.",
"shell-version": [ "3.32", "3.34", "3.36", "3.38" ], "shell-version": [ "40" ],
"localedir": "@LOCALEDIR@", "localedir": "@LOCALEDIR@",
"url": "@url@", "url": "@url@",
"version": "@version@" "version": "@version@"

@ -0,0 +1,7 @@
.openweather-dialog {
background-color: white;
padding: 10px;
}
.openweather-dialog label {
color: black;
}

File diff suppressed because it is too large Load Diff

@ -31,6 +31,7 @@
<Unit filename="data/Screenshot.jpg" /> <Unit filename="data/Screenshot.jpg" />
<Unit filename="data/metadata.json.in" /> <Unit filename="data/metadata.json.in" />
<Unit filename="data/org.gnome.shell.extensions.openweather.gschema.xml" /> <Unit filename="data/org.gnome.shell.extensions.openweather.gschema.xml" />
<Unit filename="data/prefs.css" />
<Unit filename="data/stylesheet.css" /> <Unit filename="data/stylesheet.css" />
<Unit filename="data/weather-settings.gif" /> <Unit filename="data/weather-settings.gif" />
<Unit filename="data/weather-settings.ui" /> <Unit filename="data/weather-settings.ui" />
@ -80,10 +81,7 @@
<Unit filename="src/prefs.js" /> <Unit filename="src/prefs.js" />
<Unit filename="update_revision.sh" /> <Unit filename="update_revision.sh" />
<Extensions> <Extensions>
<envvars />
<code_completion />
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
<debugger />
</Extensions> </Extensions>
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

@ -93,6 +93,15 @@ const GeolocationProvider = {
MAPQUEST: 2 MAPQUEST: 2
}; };
let provider = new Gtk.CssProvider();
provider.load_from_path(Me.dir.get_path() + '/prefs.css');
Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
let _httpSession; let _httpSession;
let mCities = null; let mCities = null;
@ -138,7 +147,10 @@ const WeatherPrefsWidget = new GObject.Class({
this.editCoord = this.Window.get_object("edit-coord"); this.editCoord = this.Window.get_object("edit-coord");
this.editCombo = this.Window.get_object("edit-combo"); this.editCombo = this.Window.get_object("edit-combo");
this.searchWidget = this.Window.get_object("search-widget"); this.searchWidget = this.Window.get_object("search-widget");
this.searchMenu = this.Window.get_object("search-menu"); this.searchMenuWidget = this.Window.get_object("search-menu-widget");
this.searchScrolledWindow = this.Window.get_object("search-scrolledwindow");
this.searchTreeview = this.Window.get_object("search-treeview");
this.searchListstore = this.Window.get_object("search-liststore");
this.searchName = this.Window.get_object("search-name"); this.searchName = this.Window.get_object("search-name");
this.searchCombo = this.Window.get_object("search-combo"); this.searchCombo = this.Window.get_object("search-combo");
@ -147,7 +159,9 @@ const WeatherPrefsWidget = new GObject.Class({
this.editCoord.connect("icon-release", Lang.bind(this, this.clearEntry)); this.editCoord.connect("icon-release", Lang.bind(this, this.clearEntry));
this.Window.get_object("tree-toolbutton-add").connect("clicked", Lang.bind(this, function() { this.Window.get_object("tree-toolbutton-add").connect("clicked", Lang.bind(this, function() {
this.searchWidget.show_all(); this.searchName.set_text("");
this.clearSearchMenu();
this.searchWidget.show();
})); }));
this.Window.get_object("tree-toolbutton-remove").connect("clicked", Lang.bind(this, this.removeCity)); this.Window.get_object("tree-toolbutton-remove").connect("clicked", Lang.bind(this, this.removeCity));
@ -158,6 +172,11 @@ const WeatherPrefsWidget = new GObject.Class({
this.selectionChanged(selection); this.selectionChanged(selection);
})); }));
this.searchSelection = this.Window.get_object("search-selection");
this.searchSelection.connect("changed", Lang.bind(this, function(selection) {
this.searchSelectionChanged(selection);
}));
this.Window.get_object("button-edit-cancel").connect("clicked", Lang.bind(this, this.editCancel)); this.Window.get_object("button-edit-cancel").connect("clicked", Lang.bind(this, this.editCancel));
this.Window.get_object("button-edit-save").connect("clicked", Lang.bind(this, this.editSave)); this.Window.get_object("button-edit-save").connect("clicked", Lang.bind(this, this.editSave));
@ -175,13 +194,7 @@ const WeatherPrefsWidget = new GObject.Class({
if (location === "") if (location === "")
return 0; return 0;
let item = new Gtk.MenuItem(); this.appendToSearchList( _("Searching ..."));
let spinner = new Gtk.Spinner();
spinner.start();
item.add(spinner);
this.searchMenu.append(item);
this.showSearchMenu();
if (this.geolocation_provider == GeolocationProvider.OPENSTREETMAPS) { if (this.geolocation_provider == GeolocationProvider.OPENSTREETMAPS) {
let params = { let params = {
@ -193,18 +206,12 @@ const WeatherPrefsWidget = new GObject.Class({
this.loadJsonAsync(OPENWEATHER_URL_OSM_FIND, params, Lang.bind(this, function() { this.loadJsonAsync(OPENWEATHER_URL_OSM_FIND, params, Lang.bind(this, function() {
this.clearSearchMenu(); this.clearSearchMenu();
if (!arguments[0]) { if (!arguments[0]) {
let item = new Gtk.MenuItem({ this.appendToSearchList(_("Invalid data when searching for \"%s\"").format(location));
label: _("Invalid data when searching for \"%s\"").format(location)
});
this.searchMenu.append(item);
} else { } else {
let newCity = arguments[0]; let newCity = arguments[0];
if (Number(newCity.length) < 1) { if (Number(newCity.length) < 1) {
let item = new Gtk.MenuItem({ this.appendToSearchList(_("\"%s\" not found").format(location));
label: _("\"%s\" not found").format(location)
});
this.searchMenu.append(item);
} else { } else {
var m = {}; var m = {};
for (var i in newCity) { for (var i in newCity) {
@ -212,11 +219,7 @@ const WeatherPrefsWidget = new GObject.Class({
let cityText = newCity[i].display_name; let cityText = newCity[i].display_name;
let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]"; let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]";
let item = new Gtk.MenuItem({ this.appendToSearchList(cityText + " " + cityCoord);
label: cityText + " " + cityCoord
});
item.connect("activate", Lang.bind(this, this.onActivateItem));
this.searchMenu.append(item);
} }
} }
} }
@ -226,14 +229,8 @@ const WeatherPrefsWidget = new GObject.Class({
} else if (this.geolocation_provider == GeolocationProvider.MAPQUEST) { } else if (this.geolocation_provider == GeolocationProvider.MAPQUEST) {
if (this.geolocation_appid_mapquest === '') { if (this.geolocation_appid_mapquest === '') {
this.clearSearchMenu(); this.clearSearchMenu();
let item = new Gtk.MenuItem({ this.appendToSearchList(_("You need an AppKey to search on openmapquest."));
label: "You need an AppKey to search on openmapquest." this.appendToSearchList(_("Please visit https://developer.mapquest.com/ ."));
});
this.searchMenu.append(item);
item = new Gtk.MenuItem({
label: "Please visit https://developer.mapquest.com/ ."
});
this.searchMenu.append(item);
this.showSearchMenu(); this.showSearchMenu();
return 0; return 0;
} }
@ -247,26 +244,14 @@ const WeatherPrefsWidget = new GObject.Class({
this.loadJsonAsync(OPENWEATHER_URL_MAPQUEST_FIND, params, Lang.bind(this, function() { this.loadJsonAsync(OPENWEATHER_URL_MAPQUEST_FIND, params, Lang.bind(this, function() {
this.clearSearchMenu(); this.clearSearchMenu();
if (!arguments[0]) { if (!arguments[0]) {
let item = new Gtk.MenuItem({ this.appendToSearchList(_("Invalid data when searching for \"%s\"").format(location));
label: _("Invalid data when searching for \"%s\"").format(location) this.appendToSearchList(_("Do you use a valid AppKey to search on openmapquest ?"));
}); this.appendToSearchList(_("If not, please visit https://developer.mapquest.com/ ."));
this.searchMenu.append(item);
item = new Gtk.MenuItem({
label: "Do you use a valid AppKey to search on openmapquest ?"
});
this.searchMenu.append(item);
item = new Gtk.MenuItem({
label: "If not, please visit https://developer.mapquest.com/ ."
});
this.searchMenu.append(item);
} else { } else {
let newCity = arguments[0]; let newCity = arguments[0];
if (Number(newCity.length) < 1) { if (Number(newCity.length) < 1) {
let item = new Gtk.MenuItem({ this.appendToSearchList(_("\"%s\" not found").format(location));
label: _("\"%s\" not found").format(location)
});
this.searchMenu.append(item);
} else { } else {
var m = {}; var m = {};
for (var i in newCity) { for (var i in newCity) {
@ -274,11 +259,7 @@ const WeatherPrefsWidget = new GObject.Class({
let cityText = newCity[i].display_name; let cityText = newCity[i].display_name;
let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]"; let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]";
let item = new Gtk.MenuItem({ this.appendToSearchList(cityText + " " + cityCoord);
label: cityText + " " + cityCoord
});
item.connect("activate", Lang.bind(this, this.onActivateItem));
this.searchMenu.append(item);
} }
} }
} }
@ -294,23 +275,14 @@ const WeatherPrefsWidget = new GObject.Class({
this.clearSearchMenu(); this.clearSearchMenu();
if (!arguments[0]) { if (!arguments[0]) {
let item = new Gtk.MenuItem({ this.appendToSearchList(_("Invalid data when searching for \"%s\"").format(location));
label: _("Invalid data when searching for \"%s\"").format(location)
});
this.searchMenu.append(item);
} else { } else {
let newCity = arguments[0].geocoding_results; let newCity = arguments[0].geocoding_results;
if (Number(newCity.length) < 1) { if (Number(newCity.length) < 1) {
let item = new Gtk.MenuItem({ this.appendToSearchList(_("Invalid data when searching for \"%s\"").format(location));
label: _("Invalid data when searching for \"%s\"").format(location)
});
this.searchMenu.append(item);
} else { } else {
if (Number(newCity.STATUS.result_count) < 1) { if (Number(newCity.STATUS.result_count) < 1) {
let item = new Gtk.MenuItem({ this.appendToSearchList(_("\"%s\" not found").format(location));
label: _("\"%s\" not found").format(location)
});
this.searchMenu.append(item);
} else { } else {
var m = {}; var m = {};
newCity = newCity.RESULTS; newCity = newCity.RESULTS;
@ -319,11 +291,7 @@ const WeatherPrefsWidget = new GObject.Class({
let cityText = newCity[i].formatted_address; let cityText = newCity[i].formatted_address;
let cityCoord = "[" + newCity[i].COORDINATES.latitude + "," + newCity[i].COORDINATES.longitude + "]"; let cityCoord = "[" + newCity[i].COORDINATES.latitude + "," + newCity[i].COORDINATES.longitude + "]";
let item = new Gtk.MenuItem({ this.appendToSearchList(cityText + " " + cityCoord);
label: cityText + " " + cityCoord
});
item.connect("activate", Lang.bind(this, this.onActivateItem));
this.searchMenu.append(item);
} }
} }
@ -372,7 +340,7 @@ const WeatherPrefsWidget = new GObject.Class({
this.treeview.append_column(column); this.treeview.append_column(column);
let renderer = new Gtk.CellRendererText(); let renderer = new Gtk.CellRendererText();
column.pack_start(renderer, null); column.pack_start(renderer, false);
column.add_attribute(renderer, "text", 0); column.add_attribute(renderer, "text", 0);
column.set_cell_data_func(renderer, function() { column.set_cell_data_func(renderer, function() {
@ -382,12 +350,22 @@ const WeatherPrefsWidget = new GObject.Class({
column.set_title(_("Provider")); column.set_title(_("Provider"));
this.treeview.append_column(column); this.treeview.append_column(column);
column.pack_start(renderer, null); column.pack_start(renderer, false);
column.add_attribute(renderer, "text", 1); column.add_attribute(renderer, "text", 1);
column.set_cell_data_func(renderer, function() { column.set_cell_data_func(renderer, function() {
arguments[1].markup = arguments[2].get_value(arguments[3], 1); arguments[1].markup = arguments[2].get_value(arguments[3], 1);
}); });
column = new Gtk.TreeViewColumn();
column.set_title(_("Result"));
this.searchTreeview.append_column(column);
column.pack_start(renderer, false);
column.add_attribute(renderer, "text", 0);
column.set_cell_data_func(renderer, function() {
arguments[1].markup = arguments[2].get_value(arguments[3], 0);
});
this.location_length_spin = this.Window.get_object("max_loc_chars"); this.location_length_spin = this.Window.get_object("max_loc_chars");
this.location_length_spin.set_value(this.loc_len_current); this.location_length_spin.set_value(this.loc_len_current);
@ -407,15 +385,15 @@ const WeatherPrefsWidget = new GObject.Class({
let theObjects = this.Window.get_objects(); let theObjects = this.Window.get_objects();
for (let i in theObjects) { for (let i in theObjects) {
let name = theObjects[i].get_name ? theObjects[i].get_name() : 'dummy'; let name = theObjects[i].get_buildable_id ? theObjects[i].get_buildable_id() : 'dummy';
if (this[name] !== undefined) { if (this[name] !== undefined) {
if (theObjects[i].class_path()[1].indexOf('GtkEntry') != -1) if (theObjects[i].get_name().indexOf('GtkEntry') != -1)
this.initEntry(theObjects[i]); this.initEntry(theObjects[i]);
else if (theObjects[i].class_path()[1].indexOf('GtkComboBoxText') != -1) else if (theObjects[i].get_name().indexOf('GtkComboBoxText') != -1)
this.initComboBox(theObjects[i]); this.initComboBox(theObjects[i]);
else if (theObjects[i].class_path()[1].indexOf('GtkSwitch') != -1) else if (theObjects[i].get_name().indexOf('GtkSwitch') != -1)
this.initSwitch(theObjects[i]); this.initSwitch(theObjects[i]);
else if (theObjects[i].class_path()[1].indexOf('GtkScale') != -1) else if (theObjects[i].get_name().indexOf('GtkScale') != -1)
this.initScale(theObjects[i]); this.initScale(theObjects[i]);
this.configWidgets.push([theObjects[i], name]); this.configWidgets.push([theObjects[i], name]);
} }
@ -424,6 +402,13 @@ const WeatherPrefsWidget = new GObject.Class({
this.Window.get_object('version').set_label(Me.metadata.version.toString()); this.Window.get_object('version').set_label(Me.metadata.version.toString());
}, },
appendToSearchList: function(text) {
let current = this.searchListstore.get_iter_first();
current = this.searchListstore.append();
this.searchListstore.set_value(current, 0, text);
},
clearEntry: function() { clearEntry: function() {
arguments[0].set_text(""); arguments[0].set_text("");
}, },
@ -433,14 +418,9 @@ const WeatherPrefsWidget = new GObject.Class({
}, },
showSearchMenu: function() { showSearchMenu: function() {
this.searchMenu.show_all(); this.searchSelection.unselect_all();
if (typeof this.searchMenu.popup_at_widget === "function") { this.searchMenuWidget.show();
this.searchMenu.popup_at_widget(this.searchName, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, null); this.searchSelection.set_mode(Gtk.SelectionMode.SINGLE);
}
else
{
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
}
}, },
placeSearchMenu: function() { placeSearchMenu: function() {
@ -450,14 +430,15 @@ const WeatherPrefsWidget = new GObject.Class({
}, },
clearSearchMenu: function() { clearSearchMenu: function() {
let children = this.searchMenu.get_children(); this.searchSelection.unselect_all();
for (let i in children) { this.searchSelection.set_mode(Gtk.SelectionMode.NONE);
this.searchMenu.remove(children[i]); if (this.searchListstore !== undefined)
} this.searchListstore.clear();
this.searchMenuWidget.hide();
}, },
initEntry: function(theEntry) { initEntry: function(theEntry) {
let name = theEntry.get_name(); let name = theEntry.get_buildable_id();
theEntry.text = this[name]; theEntry.text = this[name];
if (this[name].length != 32) if (this[name].length != 32)
theEntry.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning'); theEntry.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning');
@ -473,21 +454,21 @@ const WeatherPrefsWidget = new GObject.Class({
}, },
initComboBox: function(theComboBox) { initComboBox: function(theComboBox) {
let name = theComboBox.get_name(); let name = theComboBox.get_buildable_id();
theComboBox.connect("changed", Lang.bind(this, function() { theComboBox.connect("changed", Lang.bind(this, function() {
this[name] = arguments[0].active; this[name] = arguments[0].active;
})); }));
}, },
initSwitch: function(theSwitch) { initSwitch: function(theSwitch) {
let name = theSwitch.get_name(); let name = theSwitch.get_buildable_id();
theSwitch.connect("notify::active", Lang.bind(this, function() { theSwitch.connect("notify::active", Lang.bind(this, function() {
this[name] = arguments[0].active; this[name] = arguments[0].active;
})); }));
}, },
initScale: function(theScale) { initScale: function(theScale) {
let name = theScale.get_name(); let name = theScale.get_buildable_id();
theScale.set_value(this[name]); theScale.set_value(this[name]);
this[name+'Timeout'] = undefined; this[name+'Timeout'] = undefined;
theScale.connect("value-changed", Lang.bind(this, function(slider) { theScale.connect("value-changed", Lang.bind(this, function(slider) {
@ -552,6 +533,15 @@ const WeatherPrefsWidget = new GObject.Class({
this.actual_city = parseInt(a.to_string()); this.actual_city = parseInt(a.to_string());
}, },
searchSelectionChanged: function(select) {
let a = select.get_selected_rows()[0][0];
if ( a !== undefined ) {
let b = this.searchListstore.get_iter(a);
this.searchName.set_text(this.searchListstore.get_value(b[1], 0).toString());
}
this.clearSearchMenu();
},
removeCity: function() { removeCity: function() {
let city = this.city.split(" && "); let city = this.city.split(" && ");
if (!city.length) if (!city.length)
@ -559,28 +549,26 @@ const WeatherPrefsWidget = new GObject.Class({
let ac = this.actual_city; let ac = this.actual_city;
let textDialog = _("Remove %s ?").format(this.extractLocation(city[ac])); let textDialog = _("Remove %s ?").format(this.extractLocation(city[ac]));
let dialog = new Gtk.Dialog({ let dialog = new Gtk.Dialog({
title: "" title: "",
css_classes: ['openweather-dialog']
}); });
let label = new Gtk.Label({ let label = new Gtk.Label({
label: textDialog label: textDialog
}); });
label.margin_bottom = 12; label.margin_bottom = 12;
dialog.set_border_width(12); dialog.set_modal(true);
dialog.set_modal(1); dialog.set_resizable(false);
dialog.set_resizable(0);
//dialog.set_transient_for(***** Need parent Window *****); //dialog.set_transient_for(***** Need parent Window *****);
dialog.add_button(_("No"), 0);
let d = dialog.add_button(_("Yes"), 1);
dialog.add_button(Gtk.STOCK_NO, 0); dialog.set_default_response(0);
let d = dialog.add_button(Gtk.STOCK_YES, 1);
d.set_can_default(true);
dialog.set_default(d);
let dialog_area = dialog.get_content_area(); let dialog_area = dialog.get_content_area();
dialog_area.pack_start(label, 0, 0, 0); dialog_area.append(label);
dialog.connect("response", Lang.bind(this, function(w, response_id) { dialog.connect("response", Lang.bind(this, function(w, response_id) {
if (response_id) { if (response_id == 1) {
if (city.length === 0) if (city.length === 0)
city = []; city = [];
@ -601,7 +589,7 @@ const WeatherPrefsWidget = new GObject.Class({
return 0; return 0;
})); }));
dialog.show_all(); dialog.show();
return 0; return 0;
}, },
@ -613,7 +601,7 @@ const WeatherPrefsWidget = new GObject.Class({
this.editName.set_text(this.extractLocation(city[ac])); this.editName.set_text(this.extractLocation(city[ac]));
this.editCoord.set_text(this.extractCoord(city[ac])); this.editCoord.set_text(this.extractCoord(city[ac]));
this.editCombo.set_active(this.extractProvider(city[ac]) + 1); this.editCombo.set_active(this.extractProvider(city[ac]) + 1);
this.editWidget.show_all(); this.editWidget.show();
return 0; return 0;
}, },
@ -1115,6 +1103,6 @@ function init() {
function buildPrefsWidget() { function buildPrefsWidget() {
let prefs = new WeatherPrefsWidget(); let prefs = new WeatherPrefsWidget();
let widget = prefs.mainWidget; let widget = prefs.mainWidget;
widget.show_all(); widget.show();
return widget; return widget;
} }

Loading…
Cancel
Save