Skip to content
Browse files

Added themeManager

  • Loading branch information...
1 parent 4827897 commit 43f9fefd2b8bc31a68decc618100af1282d06fd1 @clefebvre clefebvre committed
Showing with 80 additions and 2 deletions.
  1. +14 −2 data/org.cinnamon.gschema.xml.in
  2. +1 −0 js/Makefile.in
  3. +4 −0 js/ui/main.js
  4. +61 −0 js/ui/themeManager.js
View
16 data/org.cinnamon.gschema.xml.in
@@ -31,7 +31,7 @@
</_description>
</key>
<key name="favorite-apps" type="as">
- <default>[ 'epiphany.desktop', 'evolution.desktop', 'empathy.desktop', 'rhythmbox.desktop', 'shotwell.desktop', 'libreoffice-writer.desktop', 'nautilus.desktop', 'gnome-documents.desktop' ]</default>
+ <default>[ 'firefox.desktop', 'mintInstall.desktop', 'gnome-tweak-tool.desktop', 'xchat.desktop', 'gnome-terminal.desktop', 'nautilus.desktop' ]</default>
<_summary>List of desktop file IDs for favorite applications</_summary>
<_description>
The applications corresponding to these identifiers
@@ -59,10 +59,22 @@
<_summary></_summary>
</key>
<child name="clock" schema="org.cinnamon.clock"/>
+ <child name="theme" schema="org.cinnamon.theme"/>
<child name="calendar" schema="org.cinnamon.calendar"/>
<child name="recorder" schema="org.cinnamon.recorder"/>
<child name="keyboard" schema="org.cinnamon.keyboard"/>
</schema>
+
+ <schema id="org.cinnamon.theme" path="/org/cinnamon/theme/"
+ gettext-domain="@GETTEXT_PACKAGE@">
+ <key name="name" type="s">
+ <default>""</default>
+ <_summary>Theme name</_summary>
+ <_description>
+ The name of the theme
+ </_description>
+ </key>
+ </schema>
<schema id="org.cinnamon.calendar" path="/org/cinnamon/calendar/"
gettext-domain="@GETTEXT_PACKAGE@">
@@ -96,7 +108,7 @@
</_description>
</key>
<key name="show-date" type="b">
- <default>false</default>
+ <default>true</default>
<_summary>Show date in clock</_summary>
<_description>
If true, display date in the clock, in addition to time.
View
1 js/Makefile.in
@@ -361,6 +361,7 @@ nobase_dist_js_DATA = \
ui/status/volume.js \
ui/status/bluetooth.js \
ui/telepathyClient.js \
+ ui/themeManager.js \
ui/tweener.js \
ui/userMenu.js \
ui/viewSelector.js \
View
4 js/ui/main.js
@@ -34,6 +34,7 @@ const Scripting = imports.ui.scripting;
const CinnamonDBus = imports.ui.cinnamonDBus;
const TelepathyClient = imports.ui.telepathyClient;
const WindowManager = imports.ui.windowManager;
+const ThemeManager = imports.ui.themeManager;
const Magnifier = imports.ui.magnifier;
const XdndHandler = imports.ui.xdndHandler;
const StatusIconDispatcher = imports.ui.statusIconDispatcher;
@@ -66,6 +67,7 @@ let xdndHandler = null;
let statusIconDispatcher = null;
let keyboard = null;
let layoutManager = null;
+let themeManager = null;
let networkAgent = null;
let _errorLogStack = [];
let _startDate;
@@ -191,6 +193,8 @@ function start() {
_defaultCssStylesheet = global.datadir + '/theme/cinnamon.css';
_gdmCssStylesheet = global.datadir + '/theme/gdm.css';
loadTheme();
+
+ themeManager = new ThemeManager.ThemeManager();
// Set up stage hierarchy to group all UI actors under one container.
uiGroup = new Cinnamon.GenericContainer({ name: 'uiGroup' });
View
61 js/ui/themeManager.js
@@ -0,0 +1,61 @@
+// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
+// Load shell theme from ~/.themes/name/gnome-shell
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+const Lang = imports.lang;
+const Main = imports.ui.main;
+
+const SETTINGS_SCHEMA = 'org.cinnamon.theme';
+const SETTINGS_KEY = 'name';
+
+function ThemeManager() {
+ this._init();
+}
+
+ThemeManager.prototype = {
+ _init: function() {
+ this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
+ this._changedId = this._settings.connect('changed::'+SETTINGS_KEY, Lang.bind(this, this._changeTheme));
+ this._changeTheme();
+ },
+
+ _findTheme: function(themeName, cssPath) {
+ let stylesheet = null;
+ let _userCssStylesheet = GLib.get_home_dir() + '/.themes/' + themeName + cssPath;
+ let file = Gio.file_new_for_path(_userCssStylesheet);
+ if (file.query_exists(null))
+ stylesheet = _userCssStylesheet;
+ else {
+ let sysdirs = GLib.get_system_data_dirs();
+ for (let i = 0; i < sysdirs.length; i++) {
+ _userCssStylesheet = sysdirs[i] + '/themes/' + themeName + cssPath;
+ let file = Gio.file_new_for_path(_userCssStylesheet);
+ if (file.query_exists(null)) {
+ stylesheet = _userCssStylesheet;
+ break;
+ }
+ }
+ }
+ return stylesheet;
+ },
+
+ _changeTheme: function() {
+ let _stylesheet = null;
+ let _themeName = this._settings.get_string(SETTINGS_KEY);
+
+ if (_themeName) {
+ _stylesheet = this._findTheme(_themeName, '/cinnamon/cinnamon.css');
+ if (_stylesheet == null) {
+ _stylesheet = this._findTheme(_themeName, '/gnome-shell/gnome-shell.css');
+ }
+ }
+
+ if (_stylesheet)
+ global.log('loading user theme: ' + _stylesheet);
+ else
+ global.log('loading default theme');
+ Main.setThemeStylesheet(_stylesheet);
+ Main.loadTheme();
+ }
+};

0 comments on commit 43f9fef

Please sign in to comment.
Something went wrong with that request. Please try again.