2009-12-18 02:55:02 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <stdio.h>
|
2012-05-17 20:48:20 +04:00
|
|
|
#include <stdint.h>
|
2009-12-18 02:55:02 +03:00
|
|
|
#include <sys/stat.h>
|
2010-01-22 02:56:25 +03:00
|
|
|
#include <unistd.h>
|
2011-01-30 02:40:22 +03:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/content_type.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/hlcache.h"
|
2012-05-17 20:48:20 +04:00
|
|
|
#include "gtk/compat.h"
|
2011-01-30 02:40:22 +03:00
|
|
|
#include "gtk/gui.h"
|
|
|
|
#include "gtk/scaffolding.h"
|
|
|
|
#include "gtk/menu.h"
|
|
|
|
#include "gtk/theme.h"
|
|
|
|
#include "gtk/window.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2012-12-30 05:17:17 +04:00
|
|
|
#include "gtk/dialogs/preferences.h"
|
2009-12-18 02:55:02 +03:00
|
|
|
#include "utils/container.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
|
|
|
enum image_sets {
|
|
|
|
IMAGE_SET_MAIN_MENU = 0,
|
|
|
|
IMAGE_SET_RCLICK_MENU,
|
|
|
|
IMAGE_SET_POPUP_MENU,
|
|
|
|
IMAGE_SET_BUTTONS,
|
|
|
|
IMAGE_SET_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsgtk_theme_cache {
|
|
|
|
GdkPixbuf *image[PLACEHOLDER_BUTTON];
|
|
|
|
GdkPixbuf *searchimage[SEARCH_BUTTONS_COUNT];
|
|
|
|
/* apng throbber image */
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *current_theme_name = NULL;
|
|
|
|
static struct nsgtk_theme_cache *theme_cache_menu = NULL;
|
|
|
|
static struct nsgtk_theme_cache *theme_cache_toolbar = NULL;
|
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
/**
|
|
|
|
* \param themename contains a name of theme to check whether it may
|
|
|
|
* properly be added to the list; alternatively NULL to check the integrity
|
|
|
|
* of the list
|
|
|
|
* \return true for themename may be added / every item in the list is
|
|
|
|
* a valid directory
|
|
|
|
*/
|
|
|
|
|
|
|
|
static bool nsgtk_theme_verify(const char *themename)
|
|
|
|
{
|
|
|
|
long filelength;
|
|
|
|
FILE *fp;
|
|
|
|
size_t val = SLEN("themelist") + strlen(res_dir_location) + 1;
|
|
|
|
char buf[50];
|
|
|
|
char themefile[val];
|
|
|
|
snprintf(themefile, val, "%s%s", res_dir_location, "themelist");
|
|
|
|
if (themename == NULL) {
|
|
|
|
char *filecontent, *testfile;
|
|
|
|
struct stat sta;
|
|
|
|
fp = fopen(themefile, "r+");
|
|
|
|
if (fp == NULL) {
|
|
|
|
warn_user(messages_get("gtkFileError"), themefile);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
fseek(fp, 0L, SEEK_END);
|
|
|
|
filelength = ftell(fp);
|
|
|
|
filecontent = malloc(filelength +
|
|
|
|
SLEN("gtk default theme\n") + SLEN("\n")
|
|
|
|
+ 1);
|
|
|
|
if (filecontent == NULL) {
|
|
|
|
warn_user(messages_get("NoMemory"), 0);
|
|
|
|
fclose(fp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
strcpy(filecontent, "gtk default theme\n");
|
|
|
|
fseek(fp, 0L, SEEK_SET);
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
|
|
/* iterate list */
|
|
|
|
buf[strlen(buf) - 1] = '\0';
|
|
|
|
/* "\n\0" -> "\0\0" */
|
|
|
|
testfile = malloc(strlen(res_dir_location) +
|
|
|
|
SLEN("themes/") + strlen(buf) + 1);
|
|
|
|
if (testfile == NULL) {
|
|
|
|
warn_user(messages_get("NoMemory"), 0);
|
|
|
|
free(filecontent);
|
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sprintf(testfile, "%sthemes/%s", res_dir_location,
|
|
|
|
buf);
|
|
|
|
/* check every directory */
|
|
|
|
if (access(testfile, R_OK) == 0) {
|
|
|
|
stat(testfile, &sta);
|
|
|
|
if (S_ISDIR(sta.st_mode)) {
|
|
|
|
buf[strlen(buf)] = '\n';
|
|
|
|
/* "\0\0" -> "\n\0" */
|
|
|
|
strcat(filecontent, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(testfile);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
fp = fopen(themefile, "w");
|
|
|
|
if (fp == NULL) {
|
|
|
|
warn_user(messages_get("gtkFileError"), themefile);
|
|
|
|
free(filecontent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
val = fwrite(filecontent, strlen(filecontent), 1, fp);
|
|
|
|
if (val == 0)
|
|
|
|
LOG(("empty write themelist"));
|
|
|
|
fclose(fp);
|
|
|
|
free(filecontent);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
fp = fopen(themefile, "r");
|
|
|
|
if (fp == NULL) {
|
|
|
|
warn_user(messages_get("gtkFileError"), themefile);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
|
|
buf[strlen(buf) - 1] = '\0';
|
|
|
|
/* "\n\0" -> "\0\0" */
|
|
|
|
if (strcmp(buf, themename) == 0) {
|
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* called during gui init phase to retrieve theme name from file then
|
|
|
|
* implement
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsgtk_theme_init(void)
|
|
|
|
{
|
2012-12-30 05:17:17 +04:00
|
|
|
int theme;
|
|
|
|
nsgtk_scaffolding *list = scaf_list;
|
|
|
|
FILE *fp;
|
|
|
|
char buf[50];
|
|
|
|
int row_count = 0;
|
|
|
|
|
|
|
|
theme = nsoption_int(current_theme);
|
|
|
|
|
|
|
|
/* check if default theme is selected */
|
|
|
|
if (theme == 0) {
|
2009-12-18 02:55:02 +03:00
|
|
|
return;
|
2011-08-14 02:02:36 +04:00
|
|
|
}
|
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_theme_verify(NULL);
|
2012-12-30 05:17:17 +04:00
|
|
|
fp = fopen(themelist_file_location, "r");
|
2009-12-18 02:55:02 +03:00
|
|
|
if (fp == NULL)
|
|
|
|
return;
|
2012-12-30 05:17:17 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
|
|
if (buf[0] == '\0')
|
|
|
|
continue;
|
|
|
|
|
2012-12-30 05:17:17 +04:00
|
|
|
if (row_count++ == theme) {
|
|
|
|
if (current_theme_name != NULL) {
|
2009-12-18 02:55:02 +03:00
|
|
|
free(current_theme_name);
|
2012-12-30 05:17:17 +04:00
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
/* clear the '\n' ["\n\0"->"\0\0"] */
|
|
|
|
buf[strlen(buf) - 1] = '\0';
|
|
|
|
current_theme_name = strdup(buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
while (list != NULL) {
|
|
|
|
nsgtk_theme_implement(list);
|
|
|
|
list = nsgtk_scaffolding_iterate(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return reference to static global current_theme_name; caller then has
|
|
|
|
* responsibility for global reference
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *nsgtk_theme_name(void)
|
|
|
|
{
|
|
|
|
return current_theme_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-12-30 05:17:17 +04:00
|
|
|
* set static global current_theme_name from param
|
2009-12-18 02:55:02 +03:00
|
|
|
*/
|
|
|
|
|
2012-12-30 05:17:17 +04:00
|
|
|
void nsgtk_theme_set_name(const char *name)
|
2009-12-18 02:55:02 +03:00
|
|
|
{
|
2012-12-30 05:17:17 +04:00
|
|
|
if ((name == NULL) && (current_theme_name == NULL)) {
|
|
|
|
return; /* setting it to the same thing */
|
|
|
|
} else if ((name == NULL) && (current_theme_name != NULL)) {
|
|
|
|
free(current_theme_name);
|
|
|
|
current_theme_name = NULL;
|
|
|
|
} else if ((name != NULL) && (current_theme_name == NULL)) {
|
|
|
|
current_theme_name = strdup(name);
|
|
|
|
nsgtk_theme_prepare();
|
|
|
|
} else if (strcmp(name, current_theme_name) != 0) {
|
|
|
|
/* disimilar new name */
|
|
|
|
free(current_theme_name);
|
|
|
|
current_theme_name = strdup(name);
|
|
|
|
nsgtk_theme_prepare();
|
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* adds a theme name to the list of themes
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsgtk_theme_add(const char *themename)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
GtkWidget *notification, *label;
|
|
|
|
len = SLEN("themelist") + strlen(res_dir_location) + 1;
|
|
|
|
char themefile[len];
|
|
|
|
snprintf(themefile, len, "%s%s", res_dir_location, "themelist");
|
|
|
|
/* conduct verification here; no adding duplicates to list */
|
|
|
|
if (nsgtk_theme_verify(themename) == false) {
|
|
|
|
warn_user(messages_get("gtkThemeDup"), 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FILE *fp = fopen(themefile, "a");
|
|
|
|
if (fp == NULL) {
|
|
|
|
warn_user(messages_get("gtkFileError"), themefile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(fp, "%s\n", themename);
|
|
|
|
fclose(fp);
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
/* notification that theme was added successfully */
|
|
|
|
notification = gtk_dialog_new_with_buttons(messages_get("gtkThemeAdd"),
|
|
|
|
NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK,
|
|
|
|
GTK_RESPONSE_NONE, NULL);
|
|
|
|
if (notification == NULL) {
|
|
|
|
warn_user(messages_get("NoMemory"), 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
len = SLEN("\t\t\t\t\t\t") + strlen(messages_get("gtkThemeAdd")) + 1;
|
|
|
|
char labelcontent[len];
|
|
|
|
snprintf(labelcontent, len, "\t\t\t%s\t\t\t",
|
2011-08-14 02:02:36 +04:00
|
|
|
messages_get("gtkThemeAdd"));
|
2009-12-18 02:55:02 +03:00
|
|
|
label = gtk_label_new(labelcontent);
|
|
|
|
if (label == NULL) {
|
|
|
|
warn_user(messages_get("NoMemory"), 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_signal_connect_swapped(notification, "response",
|
2011-08-14 02:02:36 +04:00
|
|
|
G_CALLBACK(gtk_widget_destroy), notification);
|
2012-05-17 20:48:20 +04:00
|
|
|
gtk_container_add(GTK_CONTAINER(nsgtk_dialog_get_action_area(GTK_DIALOG(notification))), label);
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_widget_show_all(notification);
|
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
/* update combo */
|
2012-12-30 05:17:17 +04:00
|
|
|
nsgtk_preferences_theme_add(themename);
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
/**
|
|
|
|
* sets the images for a particular scaffolding according to the current theme
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsgtk_theme_implement(struct gtk_scaffolding *g)
|
|
|
|
{
|
|
|
|
struct nsgtk_theme *theme[IMAGE_SET_COUNT];
|
|
|
|
int i;
|
|
|
|
struct nsgtk_button_connect *button;
|
|
|
|
struct gtk_search *search;
|
|
|
|
|
|
|
|
for (i = 0; i <= IMAGE_SET_POPUP_MENU; i++)
|
|
|
|
theme[i] = nsgtk_theme_load(GTK_ICON_SIZE_MENU);
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
theme[IMAGE_SET_BUTTONS] =
|
2011-08-14 02:02:36 +04:00
|
|
|
nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR);
|
2009-12-18 02:55:02 +03:00
|
|
|
|
|
|
|
for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) {
|
2011-08-14 02:02:36 +04:00
|
|
|
if ((i == URL_BAR_ITEM) || (i == THROBBER_ITEM) ||
|
|
|
|
(i == WEBSEARCH_ITEM))
|
2009-12-18 02:55:02 +03:00
|
|
|
continue;
|
|
|
|
button = nsgtk_scaffolding_button(g, i);
|
|
|
|
if (button == NULL)
|
|
|
|
continue;
|
|
|
|
/* gtk_image_menu_item_set_image accepts NULL image */
|
2011-08-14 02:02:36 +04:00
|
|
|
if ((button->main != NULL) &&
|
|
|
|
(theme[IMAGE_SET_MAIN_MENU] != NULL)) {
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_image_menu_item_set_image(button->main,
|
2011-08-14 02:02:36 +04:00
|
|
|
GTK_WIDGET(
|
|
|
|
theme[IMAGE_SET_MAIN_MENU]->
|
|
|
|
image[i]));
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(button->main));
|
|
|
|
}
|
2011-08-14 02:02:36 +04:00
|
|
|
if ((button->rclick != NULL) &&
|
|
|
|
(theme[IMAGE_SET_RCLICK_MENU] != NULL)) {
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_image_menu_item_set_image(button->rclick,
|
2011-08-14 02:02:36 +04:00
|
|
|
GTK_WIDGET(
|
|
|
|
theme[IMAGE_SET_RCLICK_MENU]->
|
|
|
|
image[i]));
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(button->rclick));
|
|
|
|
}
|
2011-08-14 02:02:36 +04:00
|
|
|
if ((button->popup != NULL) &&
|
|
|
|
(theme[IMAGE_SET_POPUP_MENU] != NULL)) {
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_image_menu_item_set_image(button->popup,
|
2011-08-14 02:02:36 +04:00
|
|
|
GTK_WIDGET(
|
|
|
|
theme[IMAGE_SET_POPUP_MENU]->
|
|
|
|
image[i]));
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(button->popup));
|
|
|
|
}
|
2011-08-14 02:02:36 +04:00
|
|
|
if ((button->location != -1) && (button->button != NULL) &&
|
|
|
|
(theme[IMAGE_SET_BUTTONS] != NULL)) {
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_tool_button_set_icon_widget(
|
2011-08-14 02:02:36 +04:00
|
|
|
GTK_TOOL_BUTTON(button->button),
|
|
|
|
GTK_WIDGET(
|
2009-12-18 02:55:02 +03:00
|
|
|
theme[IMAGE_SET_BUTTONS]->
|
|
|
|
image[i]));
|
|
|
|
gtk_widget_show_all(GTK_WIDGET(button->button));
|
|
|
|
}
|
|
|
|
}
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
/* set search bar images */
|
|
|
|
search = nsgtk_scaffolding_search(g);
|
|
|
|
if ((search != NULL) && (theme[IMAGE_SET_MAIN_MENU] != NULL)) {
|
|
|
|
/* gtk_tool_button_set_icon_widget accepts NULL image */
|
|
|
|
if (search->buttons[SEARCH_BACK_BUTTON] != NULL) {
|
|
|
|
gtk_tool_button_set_icon_widget(
|
2011-08-14 02:02:36 +04:00
|
|
|
search->buttons[SEARCH_BACK_BUTTON],
|
|
|
|
GTK_WIDGET(theme[IMAGE_SET_MAIN_MENU]->
|
|
|
|
searchimage[SEARCH_BACK_BUTTON]));
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(
|
2011-08-14 02:02:36 +04:00
|
|
|
search->buttons[SEARCH_BACK_BUTTON]));
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
if (search->buttons[SEARCH_FORWARD_BUTTON] != NULL) {
|
|
|
|
gtk_tool_button_set_icon_widget(
|
2011-08-14 02:02:36 +04:00
|
|
|
search->buttons[SEARCH_FORWARD_BUTTON],
|
|
|
|
GTK_WIDGET(theme[IMAGE_SET_MAIN_MENU]->
|
|
|
|
searchimage[SEARCH_FORWARD_BUTTON]));
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(
|
2011-08-14 02:02:36 +04:00
|
|
|
search->buttons[
|
|
|
|
SEARCH_FORWARD_BUTTON]));
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
if (search->buttons[SEARCH_CLOSE_BUTTON] != NULL) {
|
|
|
|
gtk_tool_button_set_icon_widget(
|
2011-08-14 02:02:36 +04:00
|
|
|
search->buttons[SEARCH_CLOSE_BUTTON],
|
|
|
|
GTK_WIDGET(theme[IMAGE_SET_MAIN_MENU]->
|
|
|
|
searchimage[SEARCH_CLOSE_BUTTON]));
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(
|
2011-08-14 02:02:36 +04:00
|
|
|
search->buttons[SEARCH_CLOSE_BUTTON]));
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
}
|
2011-08-14 02:02:36 +04:00
|
|
|
for (i = 0; i < IMAGE_SET_COUNT; i++) {
|
|
|
|
if (theme[i] != NULL) {
|
2009-12-18 02:55:02 +03:00
|
|
|
free(theme[i]);
|
2011-08-14 02:02:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns default image for buttons / menu items from gtk stock items
|
|
|
|
* \param tbbutton button reference
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GtkImage *
|
|
|
|
nsgtk_theme_image_default(nsgtk_toolbar_button tbbutton, GtkIconSize iconsize)
|
|
|
|
{
|
|
|
|
GtkImage *image; /* The GTK image to return */
|
|
|
|
char *imagefile;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
switch(tbbutton) {
|
|
|
|
|
|
|
|
#define BUTTON_IMAGE(p, q) \
|
|
|
|
case p##_BUTTON: \
|
|
|
|
image = GTK_IMAGE(gtk_image_new_from_stock(#q, iconsize)); \
|
|
|
|
break
|
|
|
|
|
|
|
|
BUTTON_IMAGE(BACK, gtk-go-back);
|
|
|
|
BUTTON_IMAGE(FORWARD, gtk-go-forward);
|
|
|
|
BUTTON_IMAGE(STOP, gtk-stop);
|
|
|
|
BUTTON_IMAGE(RELOAD, gtk-refresh);
|
|
|
|
BUTTON_IMAGE(HOME, gtk-home);
|
|
|
|
BUTTON_IMAGE(NEWWINDOW, gtk-new);
|
|
|
|
BUTTON_IMAGE(NEWTAB, gtk-new);
|
|
|
|
BUTTON_IMAGE(OPENFILE, gtk-open);
|
|
|
|
BUTTON_IMAGE(CLOSETAB, gtk-close);
|
|
|
|
BUTTON_IMAGE(CLOSEWINDOW, gtk-close);
|
|
|
|
BUTTON_IMAGE(SAVEPAGE, gtk-save-as);
|
|
|
|
BUTTON_IMAGE(PRINTPREVIEW, gtk-print-preview);
|
|
|
|
BUTTON_IMAGE(PRINT, gtk-print);
|
|
|
|
BUTTON_IMAGE(QUIT, gtk-quit);
|
|
|
|
BUTTON_IMAGE(CUT, gtk-cut);
|
|
|
|
BUTTON_IMAGE(COPY, gtk-copy);
|
|
|
|
BUTTON_IMAGE(PASTE, gtk-paste);
|
|
|
|
BUTTON_IMAGE(DELETE, gtk-delete);
|
|
|
|
BUTTON_IMAGE(SELECTALL, gtk-select-all);
|
|
|
|
BUTTON_IMAGE(FIND, gtk-find);
|
|
|
|
BUTTON_IMAGE(PREFERENCES, gtk-preferences);
|
|
|
|
BUTTON_IMAGE(ZOOMPLUS, gtk-zoom-in);
|
|
|
|
BUTTON_IMAGE(ZOOMMINUS, gtk-zoom-out);
|
|
|
|
BUTTON_IMAGE(ZOOMNORMAL, gtk-zoom-100);
|
|
|
|
BUTTON_IMAGE(FULLSCREEN, gtk-fullscreen);
|
|
|
|
BUTTON_IMAGE(VIEWSOURCE, gtk-index);
|
|
|
|
BUTTON_IMAGE(CONTENTS, gtk-help);
|
|
|
|
BUTTON_IMAGE(ABOUT, gtk-about);
|
|
|
|
#undef BUTTON_IMAGE
|
|
|
|
|
|
|
|
case HISTORY_BUTTON:
|
|
|
|
len = SLEN("arrow_down_8x32.png") +strlen(res_dir_location) + 1;
|
|
|
|
imagefile = malloc(len);
|
|
|
|
if (imagefile == NULL) {
|
|
|
|
warn_user(messages_get("NoMemory"), 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
snprintf(imagefile, len, "%sarrow_down_8x32.png",
|
|
|
|
res_dir_location);
|
|
|
|
image = GTK_IMAGE(gtk_image_new_from_file(imagefile));
|
|
|
|
free(imagefile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
len = SLEN("themes/Alpha.png") + strlen(res_dir_location) + 1;
|
|
|
|
imagefile = malloc(len);
|
|
|
|
if (imagefile == NULL) {
|
|
|
|
warn_user(messages_get("NoMemory"), 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
snprintf(imagefile, len, "%sthemes/Alpha.png",res_dir_location);
|
|
|
|
image = GTK_IMAGE(gtk_image_new_from_file(imagefile));
|
|
|
|
free(imagefile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns default image for search buttons / menu items from gtk stock items
|
|
|
|
* \param tbbutton button reference
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GtkImage *
|
|
|
|
nsgtk_theme_searchimage_default(nsgtk_search_buttons tbbutton,
|
|
|
|
GtkIconSize iconsize)
|
|
|
|
{
|
|
|
|
char *imagefile;
|
|
|
|
GtkImage *image;
|
|
|
|
switch(tbbutton) {
|
|
|
|
|
|
|
|
case (SEARCH_BACK_BUTTON):
|
|
|
|
return GTK_IMAGE(gtk_image_new_from_stock("gtk-go-back", iconsize));
|
|
|
|
case (SEARCH_FORWARD_BUTTON):
|
|
|
|
return GTK_IMAGE(gtk_image_new_from_stock("gtk-go-forward",
|
|
|
|
iconsize));
|
|
|
|
case (SEARCH_CLOSE_BUTTON):
|
|
|
|
return GTK_IMAGE(gtk_image_new_from_stock("gtk-close", iconsize));
|
|
|
|
default: {
|
|
|
|
size_t len = SLEN("themes/Alpha.png") +
|
|
|
|
strlen(res_dir_location) + 1;
|
|
|
|
imagefile = malloc(len);
|
|
|
|
if (imagefile == NULL) {
|
|
|
|
warn_user(messages_get("NoMemory"), 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
snprintf(imagefile, len, "%sthemes/Alpha.png",
|
|
|
|
res_dir_location);
|
|
|
|
image = GTK_IMAGE(
|
|
|
|
gtk_image_new_from_file(imagefile));
|
|
|
|
free(imagefile);
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* loads the set of default images for the toolbar / menus
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct nsgtk_theme *nsgtk_theme_default(GtkIconSize iconsize)
|
|
|
|
{
|
|
|
|
struct nsgtk_theme *theme = malloc(sizeof(struct nsgtk_theme));
|
|
|
|
int btnloop;
|
|
|
|
|
|
|
|
if (theme == NULL) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (btnloop = BACK_BUTTON; btnloop < PLACEHOLDER_BUTTON ; btnloop++) {
|
|
|
|
theme->image[btnloop] = nsgtk_theme_image_default(btnloop, iconsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (btnloop = SEARCH_BACK_BUTTON; btnloop < SEARCH_BUTTONS_COUNT; btnloop++) {
|
|
|
|
theme->searchimage[btnloop] = nsgtk_theme_searchimage_default(btnloop, iconsize);
|
|
|
|
}
|
|
|
|
return theme;
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* creates a set of images to add to buttons / menus
|
|
|
|
* loads images from cache, calling an update to the cache when necessary
|
|
|
|
* \return a struct nsgtk_theme is an array of images
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct nsgtk_theme *nsgtk_theme_load(GtkIconSize s)
|
|
|
|
{
|
2011-08-14 02:02:36 +04:00
|
|
|
if (current_theme_name == NULL) {
|
2009-12-18 02:55:02 +03:00
|
|
|
return nsgtk_theme_default(s);
|
2011-08-14 02:02:36 +04:00
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
|
|
|
|
struct nsgtk_theme *theme = malloc(sizeof(struct nsgtk_theme));
|
2011-08-14 02:02:36 +04:00
|
|
|
if (theme == NULL) {
|
2009-12-18 23:15:50 +03:00
|
|
|
return theme;
|
2011-08-14 02:02:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((theme_cache_menu == NULL) || (theme_cache_toolbar == NULL)) {
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_theme_prepare();
|
2011-08-14 02:02:36 +04:00
|
|
|
}
|
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
/* load theme from cache */
|
|
|
|
struct nsgtk_theme_cache *cachetheme = (s == GTK_ICON_SIZE_MENU) ?
|
2011-08-14 02:02:36 +04:00
|
|
|
theme_cache_menu : theme_cache_toolbar;
|
2009-12-18 23:15:50 +03:00
|
|
|
if (cachetheme == NULL) {
|
|
|
|
free(theme);
|
2009-12-18 02:55:02 +03:00
|
|
|
return NULL;
|
2009-12-18 23:15:50 +03:00
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
#define SET_BUTTON_IMAGE(p, q, r) \
|
|
|
|
if (p->image[q##_BUTTON] != NULL) \
|
|
|
|
r->image[q##_BUTTON] = GTK_IMAGE(gtk_image_new_from_pixbuf( \
|
|
|
|
p->image[q##_BUTTON])); \
|
|
|
|
else \
|
|
|
|
r->image[q##_BUTTON] = nsgtk_theme_image_default(q##_BUTTON, s)
|
|
|
|
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, BACK, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, HISTORY, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, FORWARD, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, STOP, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, RELOAD, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, HOME, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, NEWWINDOW, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, NEWTAB, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, OPENFILE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, CLOSETAB, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, CLOSEWINDOW, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, SAVEPAGE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, PRINTPREVIEW, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, PRINT, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, QUIT, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, CUT, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, COPY, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, PASTE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, DELETE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, SELECTALL, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, PREFERENCES, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, ZOOMPLUS, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, ZOOMMINUS, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, ZOOMNORMAL, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, FULLSCREEN, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, VIEWSOURCE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, CONTENTS, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, ABOUT, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, PDF, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, PLAINTEXT, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, DRAWFILE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, POSTSCRIPT, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, FIND, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, DOWNLOADS, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, SAVEWINDOWSIZE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, TOGGLEDEBUGGING, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, SAVEBOXTREE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, SAVEDOMTREE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, LOCALHISTORY, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, GLOBALHISTORY, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, ADDBOOKMARKS, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, SHOWBOOKMARKS, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, SHOWCOOKIES, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, OPENLOCATION, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, NEXTTAB, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, PREVTAB, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, GUIDE, theme);
|
|
|
|
SET_BUTTON_IMAGE(cachetheme, INFO, theme);
|
2009-12-18 02:55:02 +03:00
|
|
|
#undef SET_BUTTON_IMAGE
|
2011-08-14 02:02:36 +04:00
|
|
|
|
|
|
|
#define SET_BUTTON_IMAGE(p, q, qq, r) \
|
|
|
|
if (qq->searchimage[SEARCH_##p##_BUTTON] != NULL) \
|
|
|
|
r->searchimage[SEARCH_##p##_BUTTON] = \
|
|
|
|
GTK_IMAGE(gtk_image_new_from_pixbuf( \
|
|
|
|
qq->searchimage[ \
|
|
|
|
SEARCH_##p##_BUTTON])); \
|
|
|
|
else if (qq->image[q##_BUTTON] != NULL) \
|
|
|
|
r->searchimage[SEARCH_##p##_BUTTON] = \
|
|
|
|
GTK_IMAGE(gtk_image_new_from_pixbuf( \
|
|
|
|
qq->image[q##_BUTTON])); \
|
|
|
|
else \
|
|
|
|
r->searchimage[SEARCH_##p##_BUTTON] = \
|
|
|
|
nsgtk_theme_searchimage_default( \
|
|
|
|
SEARCH_##p##_BUTTON, s)
|
|
|
|
|
|
|
|
SET_BUTTON_IMAGE(BACK, BACK, cachetheme, theme);
|
|
|
|
SET_BUTTON_IMAGE(FORWARD, FORWARD, cachetheme, theme);
|
|
|
|
SET_BUTTON_IMAGE(CLOSE, CLOSEWINDOW, cachetheme, theme);
|
|
|
|
#undef SET_BUTTON_IMAGE
|
|
|
|
return theme;
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* caches individual theme images from file
|
|
|
|
* \param i the toolbar button reference
|
|
|
|
* \param filename the image file name
|
|
|
|
* \param path the path to the theme folder
|
|
|
|
*/
|
2011-08-14 02:02:36 +04:00
|
|
|
static void
|
|
|
|
nsgtk_theme_cache_image(nsgtk_toolbar_button i, const char *filename,
|
2009-12-18 02:55:02 +03:00
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
char fullpath[strlen(filename) + strlen(path) + 1];
|
|
|
|
sprintf(fullpath, "%s%s", path, filename);
|
|
|
|
if (theme_cache_toolbar != NULL)
|
|
|
|
theme_cache_toolbar->image[i] =
|
2011-08-14 02:02:36 +04:00
|
|
|
gdk_pixbuf_new_from_file_at_size(fullpath,
|
|
|
|
24, 24, NULL);
|
|
|
|
if (theme_cache_menu != NULL) {
|
2009-12-18 02:55:02 +03:00
|
|
|
theme_cache_menu->image[i] = gdk_pixbuf_new_from_file_at_size(
|
2011-08-14 02:02:36 +04:00
|
|
|
fullpath, 16, 16, NULL);
|
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
static void
|
|
|
|
nsgtk_theme_cache_searchimage(nsgtk_search_buttons i,
|
2009-12-18 02:55:02 +03:00
|
|
|
const char *filename, const char *path)
|
|
|
|
{
|
|
|
|
char fullpath[strlen(filename) + strlen(path) + 1];
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
sprintf(fullpath, "%s%s", path, filename);
|
2011-08-14 02:02:36 +04:00
|
|
|
if (theme_cache_toolbar != NULL) {
|
2009-12-18 02:55:02 +03:00
|
|
|
theme_cache_toolbar->searchimage[i] =
|
2011-08-14 02:02:36 +04:00
|
|
|
gdk_pixbuf_new_from_file_at_size(fullpath,
|
|
|
|
24, 24, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (theme_cache_menu != NULL) {
|
2009-12-18 02:55:02 +03:00
|
|
|
theme_cache_menu->searchimage[i] =
|
2011-08-14 02:02:36 +04:00
|
|
|
gdk_pixbuf_new_from_file_at_size(fullpath,
|
|
|
|
16, 16, NULL);
|
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* caches theme images from file as pixbufs
|
|
|
|
*/
|
|
|
|
void nsgtk_theme_prepare(void)
|
|
|
|
{
|
|
|
|
if (current_theme_name == NULL)
|
|
|
|
return;
|
|
|
|
if (theme_cache_menu == NULL)
|
|
|
|
theme_cache_menu = malloc(sizeof(struct nsgtk_theme_cache));
|
|
|
|
if (theme_cache_toolbar == NULL)
|
|
|
|
theme_cache_toolbar = malloc(sizeof(struct nsgtk_theme_cache));
|
|
|
|
size_t len = strlen(res_dir_location) + SLEN("/themes/") +
|
2011-08-14 02:02:36 +04:00
|
|
|
strlen(current_theme_name) + 1;
|
2009-12-18 02:55:02 +03:00
|
|
|
char path[len];
|
2011-08-14 02:02:36 +04:00
|
|
|
snprintf(path, len, "%sthemes/%s/", res_dir_location,
|
|
|
|
current_theme_name);
|
|
|
|
#define CACHE_IMAGE(p, q, r) \
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_theme_cache_image(p##_BUTTON, #q ".png", r)
|
|
|
|
|
|
|
|
CACHE_IMAGE(BACK, back, path);
|
|
|
|
CACHE_IMAGE(HISTORY, history, path);
|
|
|
|
CACHE_IMAGE(FORWARD, forward, path);
|
|
|
|
CACHE_IMAGE(STOP, stop, path);
|
|
|
|
CACHE_IMAGE(RELOAD, reload, path);
|
|
|
|
CACHE_IMAGE(HOME, home, path);
|
|
|
|
CACHE_IMAGE(NEWWINDOW, newwindow, path);
|
|
|
|
CACHE_IMAGE(NEWTAB, newtab, path);
|
|
|
|
CACHE_IMAGE(OPENFILE, openfile, path);
|
|
|
|
CACHE_IMAGE(CLOSETAB, closetab, path);
|
|
|
|
CACHE_IMAGE(CLOSEWINDOW, closewindow, path);
|
|
|
|
CACHE_IMAGE(SAVEPAGE, savepage, path);
|
|
|
|
CACHE_IMAGE(PRINTPREVIEW, printpreview, path);
|
|
|
|
CACHE_IMAGE(PRINT, print, path);
|
|
|
|
CACHE_IMAGE(QUIT, quit, path);
|
|
|
|
CACHE_IMAGE(CUT, cut, path);
|
|
|
|
CACHE_IMAGE(COPY, copy, path);
|
|
|
|
CACHE_IMAGE(PASTE, paste, path);
|
|
|
|
CACHE_IMAGE(DELETE, delete, path);
|
|
|
|
CACHE_IMAGE(SELECTALL, selectall, path);
|
|
|
|
CACHE_IMAGE(PREFERENCES, preferences, path);
|
|
|
|
CACHE_IMAGE(ZOOMPLUS, zoomplus, path);
|
|
|
|
CACHE_IMAGE(ZOOMMINUS, zoomminus, path);
|
|
|
|
CACHE_IMAGE(ZOOMNORMAL, zoomnormal, path);
|
|
|
|
CACHE_IMAGE(FULLSCREEN, fullscreen, path);
|
|
|
|
CACHE_IMAGE(VIEWSOURCE, viewsource, path);
|
|
|
|
CACHE_IMAGE(CONTENTS, helpcontents, path);
|
|
|
|
CACHE_IMAGE(ABOUT, helpabout, path);
|
|
|
|
CACHE_IMAGE(PDF, pdf, path);
|
|
|
|
CACHE_IMAGE(PLAINTEXT, plaintext, path);
|
|
|
|
CACHE_IMAGE(DRAWFILE, drawfile, path);
|
|
|
|
CACHE_IMAGE(POSTSCRIPT, postscript, path);
|
|
|
|
CACHE_IMAGE(FIND, find, path);
|
|
|
|
CACHE_IMAGE(DOWNLOADS, downloads, path);
|
|
|
|
CACHE_IMAGE(SAVEWINDOWSIZE, savewindowsize, path);
|
|
|
|
CACHE_IMAGE(TOGGLEDEBUGGING, toggledebugging, path);
|
|
|
|
CACHE_IMAGE(SAVEBOXTREE, boxtree, path);
|
|
|
|
CACHE_IMAGE(SAVEDOMTREE, domtree, path);
|
|
|
|
CACHE_IMAGE(LOCALHISTORY, localhistory, path);
|
|
|
|
CACHE_IMAGE(GLOBALHISTORY, globalhistory, path);
|
|
|
|
CACHE_IMAGE(ADDBOOKMARKS, addbookmarks, path);
|
|
|
|
CACHE_IMAGE(SHOWBOOKMARKS, showbookmarks, path);
|
2010-10-05 23:14:46 +04:00
|
|
|
CACHE_IMAGE(SHOWCOOKIES, showcookies, path);
|
2009-12-18 02:55:02 +03:00
|
|
|
CACHE_IMAGE(OPENLOCATION, openlocation, path);
|
|
|
|
CACHE_IMAGE(NEXTTAB, nexttab, path);
|
|
|
|
CACHE_IMAGE(PREVTAB, prevtab, path);
|
|
|
|
CACHE_IMAGE(GUIDE, helpguide, path);
|
|
|
|
CACHE_IMAGE(INFO, helpinfo, path);
|
|
|
|
#undef CACHE_IMAGE
|
2011-08-14 02:02:36 +04:00
|
|
|
#define CACHE_IMAGE(p, q, r) \
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_theme_cache_searchimage(p, #q ".png", r);
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
CACHE_IMAGE(SEARCH_BACK_BUTTON, searchback, path);
|
|
|
|
CACHE_IMAGE(SEARCH_FORWARD_BUTTON, searchforward, path);
|
|
|
|
CACHE_IMAGE(SEARCH_CLOSE_BUTTON, searchclose, path);
|
|
|
|
#undef CACHE_IMAGE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_THEME_INSTALL
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
/**
|
2011-08-14 02:02:36 +04:00
|
|
|
* handler saves theme data content as a local theme
|
2009-12-18 02:55:02 +03:00
|
|
|
*/
|
2011-08-14 02:02:36 +04:00
|
|
|
|
|
|
|
static bool theme_install_read(const char *data, unsigned long len)
|
2009-12-18 02:55:02 +03:00
|
|
|
{
|
2011-08-14 02:02:36 +04:00
|
|
|
char *filename, *newfilename;
|
|
|
|
size_t namelen;
|
|
|
|
int handle = g_file_open_tmp("nsgtkthemeXXXXXX", &filename, NULL);
|
|
|
|
if (handle == -1) {
|
|
|
|
warn_user(messages_get("gtkFileError"),
|
|
|
|
"temporary theme file");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ssize_t written = write(handle, data, len);
|
|
|
|
close(handle);
|
|
|
|
if ((unsigned)written != len)
|
|
|
|
return false;
|
2009-12-18 02:55:02 +03:00
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
/* get name of theme; set as dirname */
|
|
|
|
namelen = SLEN("themes/") + strlen(res_dir_location) + 1;
|
|
|
|
char dirname[namelen];
|
|
|
|
snprintf(dirname, namelen, "%sthemes/", res_dir_location);
|
2010-04-12 03:08:54 +04:00
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
/* save individual files in theme */
|
|
|
|
newfilename = container_extract_theme(filename, dirname);
|
|
|
|
g_free(filename);
|
|
|
|
if (newfilename == NULL)
|
|
|
|
return false;
|
|
|
|
nsgtk_theme_add(newfilename);
|
|
|
|
free(newfilename);
|
2009-12-18 02:55:02 +03:00
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for theme install fetches.
|
|
|
|
*/
|
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
static nserror
|
|
|
|
theme_install_callback(hlcache_handle *c,
|
2010-04-12 03:08:54 +04:00
|
|
|
const hlcache_event *event, void *pw)
|
2009-12-18 02:55:02 +03:00
|
|
|
{
|
2010-04-12 03:08:54 +04:00
|
|
|
switch (event->type) {
|
2009-12-18 02:55:02 +03:00
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
|
|
|
const char *source_data;
|
|
|
|
unsigned long source_size;
|
|
|
|
|
|
|
|
source_data = content_get_source_data(c, &source_size);
|
2011-08-14 02:02:36 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (!theme_install_read(source_data, source_size))
|
2009-12-18 02:55:02 +03:00
|
|
|
warn_user("ThemeInvalid", 0);
|
2010-04-12 03:08:54 +04:00
|
|
|
|
|
|
|
hlcache_handle_release(c);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2011-08-14 02:02:36 +04:00
|
|
|
break;
|
2009-12-18 02:55:02 +03:00
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
2010-04-12 03:08:54 +04:00
|
|
|
warn_user(event->data.error, 0);
|
2009-12-18 02:55:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
case CONTENT_MSG_REFORMAT:
|
|
|
|
case CONTENT_MSG_REDRAW:
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-12 03:08:54 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-14 02:02:36 +04:00
|
|
|
* when CONTENT_THEME needs handling call this function
|
2009-12-18 02:55:02 +03:00
|
|
|
*/
|
2011-08-14 02:02:36 +04:00
|
|
|
void theme_install_start(hlcache_handle *c)
|
2009-12-18 02:55:02 +03:00
|
|
|
{
|
2011-08-14 02:02:36 +04:00
|
|
|
assert(c);
|
|
|
|
assert(content_get_type(c) == CONTENT_THEME);
|
2009-12-18 02:55:02 +03:00
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
/* stop theme sitting in memory cache */
|
|
|
|
content_invalidate_reuse_data(c);
|
|
|
|
|
|
|
|
hlcache_handle_replace_callback(c, theme_install_callback, NULL);
|
2009-12-18 02:55:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-14 02:02:36 +04:00
|
|
|
#endif
|