Skip to content

Commit

Permalink
Added theme selection and thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
clefebvre committed Dec 22, 2011
1 parent f6a2b48 commit bc5697b
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 23 deletions.
2 changes: 2 additions & 0 deletions data/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ dist_theme_DATA = \
theme/scroll-hhandle.svg \
theme/scroll-vhandle.svg \
theme/source-button-border.svg \
theme/thumbnail.png \
theme/thumbnail-generic.png \
theme/toggle-off-us.svg \
theme/toggle-off-intl.svg \
theme/toggle-on-us.svg \
Expand Down
31 changes: 31 additions & 0 deletions data/theme/cinnamon.css
Original file line number Diff line number Diff line change
Expand Up @@ -1888,12 +1888,43 @@ StTooltip StLabel {
/* Themes in overview */
.theme-button {
color: #CCCCCC;
padding: 10px;
margin: auto;
}

.theme-button:hover {
color: white;
background-gradient-direction: vertical;
background-gradient-start: rgba(255,255,255,0.2);
background-gradient-end: rgba(255,255,255,0.08);
box-shadow: inset 0px 0px 1px 1px rgba(255,255,255,0.06);
border-radius: 4px;
}

.theme-button:active {
color: white;
background-gradient-direction: vertical;
background-gradient-start: rgba(255,255,255,0.4);
background-gradient-end: rgba(255,255,255,0.16);
box-shadow: inset 0px 0px 1px 1px rgba(255,255,255,0.06);
border-radius: 4px;
}

.theme-box {
spacing: 3px;
}

.theme-name {
font-size: 10pt;
font-weight: bold;
color: white;
}

.theme-type {
font-size: 6pt;
font-style: italic;
}

/* Workspace Switcher */
.workspace-switcher-group {
padding: 12px;
Expand Down
Binary file added data/theme/thumbnail-generic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/theme/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 110 additions & 23 deletions js/ui/themesDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const MAX_APPLICATION_WORK_MILLIS = 75;
const MENU_POPUP_TIMEOUT = 600;
const SCROLL_TIME = 0.1;

const SETTINGS_SCHEMA = 'org.cinnamon.theme';
const SETTINGS_KEY = 'name';

const ThemeType = {
SYSTEM: 1,
PER_USER: 2
Expand All @@ -38,6 +41,10 @@ function ThemeView() {

ThemeView.prototype = {
_init: function() {

this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
this._changedId = this._settings.connect('changed::'+SETTINGS_KEY, Lang.bind(this, this._refresh));

this._grid = new IconGrid.IconGrid({ xAlign: St.Align.START });

let box = new St.BoxLayout({ vertical: true });
Expand All @@ -61,8 +68,13 @@ ThemeView.prototype = {
// Reset scroll on mapping
adjustment.value = 0;
}));

this._loadThemes();

this._refresh();
},

_refresh: function() {
this._grid.removeAll();
this._loadThemes();
},

_loadThemesIn: function(dir, type) {
Expand All @@ -87,6 +99,7 @@ ThemeView.prototype = {
},

_loadThemes: function() {
this._loadDefaultTheme();
let systemDataDirs = GLib.get_system_data_dirs();
for (let i = 0; i < systemDataDirs.length; i++) {
let dirPath = systemDataDirs[i] + '/themes';
Expand All @@ -97,26 +110,106 @@ ThemeView.prototype = {
this._loadThemesIn(Gio.file_new_for_path(GLib.build_filenamev([global.userdatadir, 'themes'])), ThemeType.PER_USER);
},

_loadTheme: function(dir, type) {
_loadDefaultTheme: function() {
let info;
let uuid = dir.get_basename();
let themeName = "Cinnamon";
let themeType = _("Default theme");
let themeDir = Gio.file_new_for_path("/usr/share/cinnamon/theme");

if (themeDir != null) {
let thumbnail = themeDir.get_child('thumbnail.png');
let icon = null;
if (thumbnail.query_exists(null)) {
icon = St.TextureCache.get_default().load_uri_sync(1, thumbnail.get_uri(), 256, 256);
}
else {
try{
let file = Gio.file_new_for_path("/usr/share/cinnamon/theme/thumbnail-generic.png");
let uri = file.get_uri();
icon = St.TextureCache.get_default().load_uri_sync(1, uri, 256, 256);
}
catch (error) {
log(error);
}
}
let theme = new St.Button({ style_class: 'theme-button', reactive: true });
let box = new St.BoxLayout({ style_class: 'theme-box', vertical: true });
if (icon != null) {
let iconBin = new St.Bin({ x_fill: true, y_fill: true });
iconBin.child = icon;
box.add(iconBin, { x_fill: false, y_fill: false } );
}
let label_name = new St.Label({ style_class: 'theme-name', text: themeName });
let bin = new St.Bin({ x_align: St.Align.MIDDLE });
bin.add_actor(label_name);
box.add(bin);
let label_type = new St.Label({ style_class: 'theme-type', text: themeType });
bin = new St.Bin({ x_align: St.Align.MIDDLE });
bin.add_actor(label_type);
box.add(bin);
theme.set_child(box);
theme.add_style_pseudo_class('active');
this._grid.addItem(theme);
theme.connect('key-focus-in', Lang.bind(this, this._ensureIconVisible));
theme.connect('clicked', Lang.bind(this, function() {
this._settings.set_string(SETTINGS_KEY, '');
}));
}
},

let gnomeshellDir = dir.get_child('gnome-shell');
let cinnamonDir = dir.get_child('cinnamon');
if (gnomeshellDir.query_exists(null) || cinnamonDir.query_exists(null)) {
_loadTheme: function(dir, type) {
let info;
let themeName = dir.get_basename();
let themeType = null;
let themeDir = null;
let cinnamonDir = dir.get_child('cinnamon');
let gnomeshellDir = dir.get_child('gnome-shell');
if (cinnamonDir.query_exists(null)) {
themeType = _("Cinnamon Theme");
themeDir = cinnamonDir;
}
else if (gnomeshellDir.query_exists(null)) {
themeType = _("Gnome Shell Theme");
themeDir = gnomeshellDir;
}

if (themeDir != null) {
let thumbnail = themeDir.get_child('thumbnail.png');
let icon = null;
if (thumbnail.query_exists(null)) {
icon = St.TextureCache.get_default().load_uri_sync(1, thumbnail.get_uri(), 256, 256);
}
else {
try{
let file = Gio.file_new_for_path("/usr/share/cinnamon/theme/thumbnail-generic.png");
let uri = file.get_uri();
icon = St.TextureCache.get_default().load_uri_sync(1, uri, 256, 256);
}
catch (error) {
log(error);
}
}
let theme = new St.Button({ style_class: 'theme-button', reactive: true });
let box = new St.BoxLayout({ style_class: 'theme-box', vertical: true });
let icon = new St.Icon({icon_name: "preferences-desktop-theme", icon_size: 48, icon_type: St.IconType.FULLCOLOR});
let iconBin = new St.Bin({ x_fill: true, y_fill: true });
iconBin.child = icon;
box.add(iconBin, { x_fill: false, y_fill: false } );
let label = new St.Label({ text: uuid });
let box = new St.BoxLayout({ style_class: 'theme-box', vertical: true });
if (icon != null) {
let iconBin = new St.Bin({ x_fill: true, y_fill: true });
iconBin.child = icon;
box.add(iconBin, { x_fill: false, y_fill: false } );
}
let label_name = new St.Label({ style_class: 'theme-name', text: themeName });
let bin = new St.Bin({ x_align: St.Align.MIDDLE });
bin.add_actor(label);
bin.add_actor(label_name);
box.add(bin);
let label_type = new St.Label({ style_class: 'theme-type', text: themeType });
bin = new St.Bin({ x_align: St.Align.MIDDLE });
bin.add_actor(label_type);
box.add(bin);
theme.set_child(box);
this._grid.addItem(theme);
theme.connect('key-focus-in', Lang.bind(this, this._ensureIconVisible));
theme.connect('key-focus-in', Lang.bind(this, this._ensureIconVisible));
theme.connect('clicked', Lang.bind(this, function() {
this._settings.set_string(SETTINGS_KEY, themeName);
}));
}
},

Expand Down Expand Up @@ -154,14 +247,8 @@ function ThemesDisplay() {

ThemesDisplay.prototype = {
_init: function() {
this.actor = new ThemeView().actor;

// this._workId = Main.initializeDeferredWork(this.actor, Lang.bind(this, this._redisplay));
}

//_redisplay: function() {
// this._view.refresh();
//}
this.actor = new ThemeView().actor;
}
};


0 comments on commit bc5697b

Please sign in to comment.