gtkpreferencewindow.cpp
字号:
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
Portions Copyright (C) 2000 EMusic.com
This program 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; either version 2 of the License, or
(at your option) any later version.
This program 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: GTKPreferenceWindow.cpp,v 1.61 2001/01/05 21:59:59 robert Exp $
____________________________________________________________________________*/
/* system headers */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <sys/stat.h>
#include <unistd.h>
#include "player.h"
#include "eventdata.h"
#include "GTKPreferenceWindow.h"
#include "GTKWindow.h"
#include "GTKFileSelector.h"
#include "MessageDialog.h"
#include "help.h"
GTKPreferenceWindow::GTKPreferenceWindow(FAContext *context,
ThemeManager *pThemeMan,
uint32 defaultPage) :
PreferenceWindow(context, pThemeMan)
{
startPage = defaultPage;
done = false;
visiblePane = NULL;
m_PMOnames = new vector<string>;
paneList = new vector<OptionsPane *>;
}
GTKPreferenceWindow::~GTKPreferenceWindow(void)
{
if (m_PMOnames)
delete m_PMOnames;
if (paneList) {
while (paneList->size() > 0) {
paneList->erase(paneList->begin());
}
delete paneList;
}
}
static gboolean pref_destroy(GtkWidget *widget, GTKPreferenceWindow *p)
{
p->done = true;
return FALSE;
}
void GTKPreferenceWindow::ApplyInfo(void)
{
if (proposedValues != currentValues)
SavePrefsValues(m_pContext->prefs, &proposedValues);
ApplyProfiles();
}
static void pref_ok_click(GtkWidget *w, GTKPreferenceWindow *p)
{
p->ApplyInfo();
gtk_widget_destroy(p->mainWindow);
p->done = true;
}
static void pref_apply_click(GtkWidget *w, GTKPreferenceWindow *p)
{
p->ApplyInfo();
}
void GTKPreferenceWindow::CancelInfo(void)
{
if (currentValues != originalValues)
SavePrefsValues(m_pContext->prefs, &originalValues);
}
static void pref_cancel_click(GtkWidget *w, GTKPreferenceWindow *p)
{
p->CancelInfo();
gtk_widget_destroy(p->mainWindow);
p->done = true;
}
void GTKPreferenceWindow::ShowHelp(void)
{
if (!::ShowHelp(m_pContext, Preferences_General))
{
MessageDialog oBox(m_pContext);
string oMessage("Cannot find the help files. Please make sure that the help files are properly installed, and you are not running "the_BRANDING" from the build directory.");
oBox.Show(oMessage.c_str(), string(BRANDING), kMessageOk, true);
}
}
static void help_click(GtkWidget *w, GTKPreferenceWindow *p)
{
p->ShowHelp();
}
void GTKPreferenceWindow::SetPane(OptionsPane *pane)
{
if (visiblePane == pane->m_pane)
return;
if (visiblePane)
gtk_widget_hide(visiblePane);
gtk_widget_show(pane->m_pane);
visiblePane = pane->m_pane;
gtk_label_set_text(GTK_LABEL(paneLabel), pane->m_description.c_str());
}
void GTKPreferenceWindow::SetPane(uint32 panenum)
{
if (paneList->size() < panenum)
return;
SetPane((*paneList)[panenum]);
}
static void pref_tree_clicked(GtkWidget *widget, GdkEventButton *event,
GTKPreferenceWindow *p)
{
if (!event)
return;
g_return_if_fail(widget != NULL);
g_return_if_fail(GTK_IS_CTREE(widget));
g_return_if_fail(event != NULL);
GtkCTree *ctree = GTK_CTREE(widget);
GtkCList *clist = GTK_CLIST(widget);
if (event->window != clist->clist_window)
return;
int row, column;
if (!gtk_clist_get_selection_info(clist, (int)event->x, (int)event->y,
&row, &column))
return;
GtkCTreeNode *node = GTK_CTREE_NODE(g_list_nth(clist->row_list, row));
OptionsPane *opane = (OptionsPane *)gtk_ctree_node_get_row_data(ctree,
node);
p->SetPane(opane);
}
static void kill_optionspane(OptionsPane *die)
{
gtk_widget_hide(die->m_pane);
gtk_widget_destroy(die->m_pane);
delete die;
}
void GTKPreferenceWindow::AddPane(OptionsPane *pane)
{
GtkCTreeNode *node;
char *name[1];
name[0] = (char *)pane->m_label.c_str();
node = gtk_ctree_insert_node(prefTree, NULL, NULL, name, 5, NULL, NULL,
NULL, NULL, true, false);
gtk_ctree_node_set_row_data_full(prefTree, node, pane,
(GtkDestroyNotify)kill_optionspane);
gtk_widget_hide(pane->m_pane);
gtk_box_pack_start(GTK_BOX(paneVbox), pane->m_pane, FALSE, FALSE, 5);
paneList->push_back(pane);
}
bool GTKPreferenceWindow::Show(Window *pWindow)
{
GetPrefsValues(m_pContext->prefs, &originalValues);
GetPrefsValues(m_pContext->prefs, &proposedValues);
GetPrefsValues(m_pContext->prefs, ¤tValues);
fontDialog = NULL;
gdk_threads_enter();
mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//gtk_window_set_modal(GTK_WINDOW(mainWindow), TRUE);
gtk_signal_connect(GTK_OBJECT(mainWindow), "destroy",
GTK_SIGNAL_FUNC(pref_destroy), this);
gtk_window_set_title(GTK_WINDOW(mainWindow), BRANDING" - Preferences");
GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(mainWindow), vbox);
gtk_widget_show(vbox);
GtkWidget *mainHbox = gtk_hbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(mainHbox), 5);
gtk_container_add(GTK_CONTAINER(vbox), mainHbox);
gtk_widget_show(mainHbox);
GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
gtk_box_pack_start(GTK_BOX(mainHbox), scrolledWindow, TRUE, TRUE, 0);
gtk_widget_set_usize(scrolledWindow, 140, 300);
gtk_widget_show(scrolledWindow);
const char *name[1];
name[0] = "Category";
prefTree = GTK_CTREE(gtk_ctree_new_with_titles(1, 0, (gchar **)name));
gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(prefTree));
gtk_signal_connect(GTK_OBJECT(prefTree), "button_press_event",
GTK_SIGNAL_FUNC(pref_tree_clicked), this);
gtk_clist_set_row_height(GTK_CLIST(prefTree), 16);
gtk_clist_column_titles_passive(GTK_CLIST(prefTree));
gtk_widget_show(GTK_WIDGET(prefTree));
paneVbox = gtk_vbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(paneVbox), 5);
gtk_box_pack_start(GTK_BOX(mainHbox), paneVbox, FALSE, FALSE, 0);
gtk_widget_show(paneVbox);
paneStyle = gtk_style_copy(gtk_widget_get_style(mainWindow));
GdkColor temp = paneStyle->bg[GTK_STATE_NORMAL];
paneStyle->bg[GTK_STATE_NORMAL] = paneStyle->fg[GTK_STATE_NORMAL];
paneStyle->fg[GTK_STATE_NORMAL] = temp;
GdkFont *font =
gdk_font_load("-adobe-helvetica-bold-r-normal--*-180-*-*-*-*-*-*");
if (font) {
gdk_font_unref(paneStyle->font);
paneStyle->font = font;
}
GtkWidget *stupid_gtk = gtk_event_box_new();
gtk_container_set_border_width(GTK_CONTAINER(stupid_gtk), 0);
gtk_box_pack_start(GTK_BOX(paneVbox), stupid_gtk, FALSE, FALSE, 0);
gtk_widget_set_style(stupid_gtk, paneStyle);
gtk_widget_show(stupid_gtk);
paneLabel = gtk_label_new(NULL);
gtk_container_add(GTK_CONTAINER(stupid_gtk), paneLabel);
gtk_widget_set_style(paneLabel, paneStyle);
gtk_label_set_justify(GTK_LABEL(paneLabel), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment(GTK_MISC(paneLabel), 0.0, 0.5);
gtk_widget_realize(paneLabel);
gtk_widget_show(paneLabel);
GtkWidget *pane;
OptionsPane *opane;
pane = CreateGeneral();
opane = new OptionsPane("General", " General Preferences", 0, pane);
AddPane(opane);
pane = CreateThemes();
opane = new OptionsPane("Themes", " Theme Preferences", 1, pane);
AddPane(opane);
pane = CreateDirectories();
opane = new OptionsPane("Directories", "Directory Preferences", 2, pane);
AddPane(opane);
pane = CreateStreaming();
opane = new OptionsPane("Streaming", " Stream Preferences", 3, pane);
AddPane(opane);
pane = CreatePlugins();
opane = new OptionsPane("Plugins", " Plugin Preferences", 4, pane);
AddPane(opane);
pane = CreateCD();
opane = new OptionsPane("CD Audio", "CD Audio Preferences", 5, pane);
AddPane(opane);
pane = CreateAdvanced();
opane = new OptionsPane("Advanced", " Advanced Preferences", 6, pane);
AddPane(opane);
pane = CreateProfiles();
opane = new OptionsPane("Relatable Profiles", " Relatable Profiles", 7,
pane);
AddPane(opane);
pane = CreatePlaylistHeaders();
opane = new OptionsPane("Playlist", "Playlist Preferences", 8, pane);
AddPane(opane);
pane = CreateAbout();
opane = new OptionsPane("About", " About "The_BRANDING, 9, pane);
AddPane(opane);
GtkWidget *separator = gtk_hseparator_new();
gtk_container_add(GTK_CONTAINER(vbox), separator);
gtk_widget_show(separator);
GtkWidget *hbox = gtk_hbox_new(FALSE, 5);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
gtk_container_add(GTK_CONTAINER(vbox), hbox);
gtk_widget_show(hbox);
GtkWidget *button;
button = gtk_button_new_with_label(" Help ");
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(help_click), this);
gtk_widget_show(button);
applyButton = gtk_button_new_with_label(" Apply ");
gtk_signal_connect(GTK_OBJECT(applyButton), "clicked",
GTK_SIGNAL_FUNC(pref_apply_click), this);
gtk_box_pack_end(GTK_BOX(hbox), applyButton, FALSE, FALSE, 0);
gtk_widget_show(applyButton);
gtk_widget_set_sensitive(applyButton, FALSE);
button = gtk_button_new_with_label(" Cancel ");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(pref_cancel_click), this);
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
button = gtk_button_new_with_label(" OK ");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(pref_ok_click), this);
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
SetPane(startPage);
gtk_widget_show(mainWindow);
firsttime = false;
gdk_threads_leave();
while (!done)
usleep(20);
return true;
}
void GTKPreferenceWindow::GetPrefsValues(Preferences* prefs,
PrefsStruct* values)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -