⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 examplewindow.cc

📁 Developing with Gnome一书examples例子代码
💻 CC
字号:
#include "ExampleWindow.h"#include <sstream>ExampleWindow::ExampleWindow(  BaseObjectType* base_object,  const Glib::RefPtr<Gnome::Glade::Xml>& glade_xml)  : Gtk::Window(base_object){  // Get the client and tell it we want to monitor /apps/nautilus/preferences  d_conf_client = Gnome::Conf::Client::get_default_client();  d_conf_client->add_dir("/apps/nautilus/preferences");  /* First, setup the checkbutton for the always_use_browser key */  // Get the check_button  glade_xml->get_widget("BrowserMode", d_browser_checkbutton);  // Connect the check_button to a callback that can toggle it when the option  // is changed by some outside program.  d_conf_client->notify_add(    "/apps/nautilus/preferences/always_use_browser",    sigc::mem_fun(*this, &ExampleWindow::browser_key_changed)    );  // Connect the check_button's clicked callback up so that it can change the  // gconf setting.  d_browser_checkbutton->signal_clicked().connect(    sigc::mem_fun(*this, &ExampleWindow::browser_key_toggled) );  // Determine whether button should start activated or not  d_old_browser_setting =     d_conf_client->get_bool("/apps/nautilus/preferences/always_use_browser");  d_browser_checkbutton->set_active(d_old_browser_setting);  /* Second, setup the text entry for the show_image_thumbnails key */  // Get the Entry  glade_xml->get_widget("ShowThumbnailsEntry", d_show_thumbnail_entry);  // Connect the show thumbnail entry to a callback that can toggle it  // when the option is changed by some outside program.  d_conf_client->notify_add(    "/apps/nautilus/preferences/show_image_thumbnails",    sigc::mem_fun(*this, &ExampleWindow::show_thumbnails_key_changed)    );  // Connect the show thumbnail entry's activated callback up so that  // it can change the gconf setting.  d_show_thumbnail_entry->signal_activate().connect(    sigc::mem_fun(*this, &ExampleWindow::show_thumbnails_modified) );  // Determine the starting value of this key  d_old_show_thumbnails_setting =    d_conf_client->get_string(      "/apps/nautilus/preferences/show_image_thumbnails");  d_show_thumbnail_entry->set_text(d_old_show_thumbnails_setting);  /* Third, setup the text entry for the thumbnail_limit key */  // Get the Entry  glade_xml->get_widget("ThumbnailLimitEntry", d_thumbnail_limit_entry);  // Connect the thumbnail limit entry to a callback that can toggle  // it when the option is changed by some outside program.  d_conf_client->notify_add(    "/apps/nautilus/preferences/thumbnail_limit",    sigc::mem_fun(*this, &ExampleWindow::thumbnail_limit_key_changed)    );  // Connect the thumbnail limit entry's activated callback up so that  // it can change the gconf setting.  d_thumbnail_limit_entry->signal_activate().connect(    sigc::mem_fun(*this, &ExampleWindow::thumbnail_limit_modified) );  // Determine the starting value of this key  d_old_thumbnail_limit =    d_conf_client->get_int("/apps/nautilus/preferences/thumbnail_limit");  gchar temp_string[20];  sprintf(temp_string, "%d", d_old_thumbnail_limit);  d_thumbnail_limit_entry->set_text(temp_string);  // Get the close button and connect it to hide  Gtk::Button* close_button;  glade_xml->get_widget("CloseButton", close_button);  close_button->signal_clicked().connect(    sigc::mem_fun(*this, &Gtk::Widget::hide));}ExampleWindow::~ExampleWindow(){}voidExampleWindow::browser_key_changed(guint cnxn_id, Gnome::Conf::Entry entry){  // Make sure the preference has a valid value  if (entry.get_value().get_type() == Gnome::Conf::VALUE_BOOL) {    // Get the new value    bool new_browser_setting = entry.get_value().get_bool();    // Try to handle asynchronous-ness of GConf and prevent calling    // checkbutton_toggled again if this function was called as a    // result of the d_conf_client->set() function call.    if (new_browser_setting != d_old_browser_setting) {      d_old_browser_setting = new_browser_setting;      d_browser_checkbutton->set_active(new_browser_setting);    }  }}voidExampleWindow::browser_key_toggled(){  // Determine whether the checkbutton is already set or not  bool is_set = d_browser_checkbutton->get_active();   // Try to handle asynchronous-ness of GConf and prevent calling  // key_changed again if this function was called as a result of the  // d_checkbutton->set_active() function call.  if (is_set != d_old_browser_setting) {    d_old_browser_setting = is_set;    d_conf_client->set("/apps/nautilus/preferences/always_use_browser", is_set);  }}voidExampleWindow::show_thumbnails_key_changed(  guint cnxn_id,   Gnome::Conf::Entry entry){  // Make sure the preference has a valid value  if (entry.get_value().get_type() == Gnome::Conf::VALUE_STRING) {    // Get the new value    Glib::ustring new_setting = entry.get_value().get_string();    // Check if it seems valid, give a warning if it doesn't    if ((new_setting != "always") &&        (new_setting != "local_only") &&        (new_setting != "never"))    {      g_warning("Unrecognized value specified by external program...\n");    }    // Use the new value if it's different than the old    if (new_setting != d_old_show_thumbnails_setting) {      d_old_show_thumbnails_setting = new_setting;      d_show_thumbnail_entry->set_text(new_setting);    }  }}voidExampleWindow::show_thumbnails_modified(){  // Get the current value  Glib::ustring cur_value = d_show_thumbnail_entry->get_text();   if ((cur_value == "always")     ||      (cur_value == "local_only") ||      (cur_value == "never")) {    if (cur_value != d_old_show_thumbnails_setting) {      d_old_show_thumbnails_setting = cur_value;      d_conf_client->set("/apps/nautilus/preferences/show_image_thumbnails",                         cur_value);    }  } else {    g_warning("This program needs an error window to warn you that you typed an invalid value.\n");    d_show_thumbnail_entry->set_text(d_old_show_thumbnails_setting);  }}voidExampleWindow::thumbnail_limit_key_changed(  guint cnxn_id,   Gnome::Conf::Entry entry){  // Make sure the preference has a valid value  if (entry.get_value().get_type() == Gnome::Conf::VALUE_INT) {    // Get the new value    gint new_value = entry.get_value().get_int();    // Check if it seems valid, give a warning if it doesn't    if (new_value < 0) {      g_warning("Bad value seems to have been set by external program.\n");    }    // Use the new value if it's different than the old    if (new_value != d_old_thumbnail_limit) {      d_old_thumbnail_limit = new_value;      gchar temp_string[20];      sprintf(temp_string, "%d", d_old_thumbnail_limit);      d_thumbnail_limit_entry->set_text(temp_string);    }  }}voidExampleWindow::thumbnail_limit_modified(){  // Get the current value  Glib::ustring cur_value = d_thumbnail_limit_entry->get_text();  /*  size_type bad_char_position = cur_value.find_first_not_of("1234567890");  gint new_value = 0;  if (bad_char_position != string::npos)    new_value = atoi(cur_value->c_str());  */  std::istringstream sstr(cur_value);  gint new_value;  sstr >> new_value;  if ( !sstr.fail() && new_value >= 0) {    if (new_value != d_old_thumbnail_limit) {      d_old_thumbnail_limit = new_value;      d_conf_client->set("/apps/nautilus/preferences/thumbnail_limit",                         new_value);    }  } else {    g_warning("This program needs an error window to warn you that you typed an invalid value.\n");    gchar temp_string[20];    sprintf(temp_string, "%d", d_old_thumbnail_limit);    d_thumbnail_limit_entry->set_text(temp_string);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -