00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "kitlistgui.hpp"
00024 #include "printing.hpp"
00025 #include <cassert>
00026
00027
00028 #ifdef MAEMO
00029 #include <hildon/hildon-help.h>
00030 #endif
00031 #include <glibmm/i18n.h>
00032 #include <glibmm/refptr.h>
00033 #include <glibmm/ustring.h>
00034 #include <gtkmm/aboutdialog.h>
00035 #include <gtkmm/cellrenderertoggle.h>
00036 #include <gtkmm/clipboard.h>
00037 #include <gtkmm/filechooserdialog.h>
00038 #include <gtkmm/menuitem.h>
00039 #include <gtkmm/messagedialog.h>
00040 #include <gtkmm/stock.h>
00041 #include <gtkmm/targetentry.h>
00042 #include <gtkmm/window.h>
00043 #include <libglademm/xml.h>
00044 #include <libxml++/libxml++.h>
00045 #include <string>
00046 #include <sstream>
00047 #include <sys/stat.h>
00048 #include <config.h>
00049
00051 #define KITLIST_SERVICE_NAME "com.nokia."PACKAGE_NAME
00053 #define KITLIST_SERVICE_OBJECT "/com/nokia/"PACKAGE_NAME
00055 #define KITLIST_SERVICE_IFACE "com.nokia."PACKAGE_NAME
00056
00057
00058 using namespace std;
00059
00060 namespace {
00061
00062 #ifdef MAEMO
00064 const string GLADE_APP_FILE = "maemo.glade";
00065 #else
00067 const string GLADE_APP_FILE = "kitlist.glade";
00068 #endif
00070 const guint SB_ITEM_COUNT = 1000;
00072 const guint SB_SAVE = SB_ITEM_COUNT + 1;
00074 const guint SB_MSG = SB_SAVE + 1;
00075
00077 const guint SB_PRINT = SB_MSG + 1;
00078
00080 const char item_target_custom[] = "kitlistclipboard";
00082 const char item_target_text[] = "text/plain";
00083
00085 const char XML_ELEMENT_ID[] = "id";
00086
00088 const Glib::ustring DEFAULT_FILENAME_EXTENSION = ".kit";
00089
00091 const Glib::ustring PDF_FILENAME_EXTENSION = ".pdf";
00092
00094 const Glib::ustring DEFAULT_FILENAME = "kitlist" + DEFAULT_FILENAME_EXTENSION;
00095
00097 #ifdef MAEMO
00098 const Glib::ustring GCONF_KEY = "/apps/maemo/kitlist";
00099 #else
00100 const Glib::ustring GCONF_KEY = "/apps/kitlist";
00101 #endif
00102
00104 const Glib::ustring GCONF_KEY_CURRENT_FILENAME = GCONF_KEY + "/current_filename";
00105
00107 const Glib::ustring GCONF_KEY_PAGE_TITLE = GCONF_KEY + "/page_title";
00108
00109 #ifdef KITLIST_DEBUG
00110 #ifdef GCONF
00112 const Glib::ustring GCONF_KEY_DEBUG_LOG = GCONF_KEY + "/debug_log_filename";
00113 #endif
00114 #endif
00115
00117 const gint DEFAULT_MAX_RECENT_FILES = 4;
00118
00120 const Glib::ustring GCONF_KEY_RECENT_FILES = GCONF_KEY + "/recent_files";
00121
00123 const Glib::ustring GCONF_KEY_MAX_RECENT_FILES = GCONF_KEY + "/max_recent_files";
00124
00125 }
00126
00127
00128 #ifdef KITLIST_DEBUG
00129 void my_log_handler(const gchar *log_domain,
00130 GLogLevelFlags log_level,
00131 const gchar *message,
00132 gpointer data) {
00133 g_print("KITLIST: %s\n", message);
00134 #ifdef MAEMO
00135 syslog(LOG_DEBUG, message);
00136 #endif
00137 ofstream* fout = (ofstream*) data;
00138 if (fout) {
00139 *fout << message << endl;
00140 }
00141 }
00142
00143 #endif
00144
00145
00146 typedef Gtk::TreeModel::Children type_children;
00147
00157 const bool file_exists(const Glib::ustring& filename) {
00158 struct stat fileinfo;
00159 bool retval;
00160 retval = !(stat(filename.c_str(), &fileinfo));
00161
00162 return retval;
00163 }
00164
00165
00167 const string load_resource_glade_file(const Glib::ustring& filename) {
00168 vector<string> locs;
00169 locs.push_back(filename);
00170 locs.push_back("../" + filename);
00171 locs.push_back("./src/" + filename);
00172 locs.push_back(string(PACKAGE_DATA_DIR) + "/glade/" + filename);
00173 for (std::vector<string>::iterator i = locs.begin(); i != locs.end(); ++i) {
00174 if (file_exists(*i))
00175 return *i;
00176 }
00177 return "";
00178 }
00179
00186 Glib::RefPtr<Gnome::Glade::Xml> get_glade_ref_ptr(const string& filename,
00187 const Glib::ustring& root = Glib::ustring(),
00188 const Glib::ustring& domain = Glib::ustring()) {
00189 Glib::RefPtr<Gnome::Glade::Xml> refXml;
00190 try {
00191 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00192 refXml = Gnome::Glade::Xml::create(load_resource_glade_file(filename), root, domain);
00193 #else
00194 std::auto_ptr<Gnome::Glade::XmlError> ex;
00195 refXml = Gnome::Glade::Xml::create(load_resource_glade_file(filename), root, domain, ex);
00196 if (ex.get())
00197 g_error(_("Error loading Glade file: %s"), ex->what().c_str());
00198 #endif
00199 } catch (const Gnome::Glade::XmlError& ex) {
00200 g_error(_("Error loading Glade file: %s"), ex.what().c_str());
00201 throw ex;
00202 }
00203 return refXml;
00204 }
00205
00206
00207 #ifdef MAEMO
00208
00209 void dump_osso_rpc_value(osso_rpc_t* retval) {
00210 switch (retval->type) {
00211 case (DBUS_TYPE_INVALID) :
00212 g_debug("invalid/void");
00213 break;
00214 case (DBUS_TYPE_STRING) :
00215 g_debug("string :'%s'", retval->value.s);
00216 break;
00217 case (DBUS_TYPE_UINT32) :
00218 g_debug("uint32 :%u", retval->value.u);
00219 break;
00220 case (DBUS_TYPE_INT32) :
00221 g_debug("int32 :%d", retval->value.i);
00222 break;
00223 case (DBUS_TYPE_BOOLEAN) :
00224 g_debug("boolean :%s", (retval->value.b == TRUE)?"TRUE":"FALSE ");
00225 break;
00226 case (DBUS_TYPE_DOUBLE) :
00227 g_debug("double :%.3f", retval->value.d);
00228 break;
00229 case (DBUS_TYPE_OBJECT_PATH) :
00230 break;
00231 default:
00232 g_debug("unknown(type=%d)", retval->type);
00233 break;
00234 }
00235 }
00236
00238 static gint dbus_req_handler(const gchar* interface, const gchar* method,
00239 GArray* arguments, gpointer data,
00240 osso_rpc_t* retval) {
00241 KitListGui* gui = (KitListGui*) data;
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 Glib::ustring smethod = method;
00256 if (smethod.compare("mime_open") == 0 && arguments->len > 0) {
00257 if (arguments->len > 0) {
00258 osso_rpc_t arg = g_array_index(arguments, osso_rpc_t, 0);
00259 if (arg.type == DBUS_TYPE_STRING) {
00260 Glib::ustring filename = arg.value.s;
00261 if (filename.find("file://") >= 0)
00262 filename.erase(0, 7);
00263 gui->raise();
00264 gui->safe_open_file(filename);
00265 }
00266 }
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 dump_osso_rpc_value(retval);
00279 osso_rpc_free_val(retval);
00280
00281 return OSSO_OK;
00282 }
00283 #endif
00284
00285
00294 KitListGui::KitListGui(int argc, char **argv, Service& service)
00295 : m_kit(argc, argv),
00296 m_ignore_list_events(false),
00297 m_window(0),
00298 m_window_preferences(0),
00299 m_entry_page_title(0),
00300 m_window_add_item(0),
00301 m_window_add_category(0),
00302 m_entry_add_item(0),
00303 m_entry_add_category(0),
00304 m_file_save_menu_item(0),
00305 m_file_save_tool_button(0),
00306 m_paste_menu_item(0),
00307 m_paste_tool_button(0),
00308 m_checkbutton_add_item(0),
00309 m_category_combo(0),
00310 m_item_tree_view(0),
00311 m_ref_item_tree_model(0),
00312 m_service(service),
00313 m_status_bar(0),
00314 m_state(ADD_CATEGORY),
00315 #ifdef MAEMO
00316 m_full_screen(false),
00317 #endif
00318 m_current_cat_id(-1) {
00319 m_ref_page_setup = Gtk::PageSetup::create();
00320 m_ref_printer_settings = Gtk::PrintSettings::create();
00321 init();
00322 }
00323
00324
00325 KitListGui::~KitListGui() {
00326 #ifdef KITLIST_DEBUG
00327 if (m_slog) {
00328 m_slog->close();
00329 delete m_slog;
00330 }
00331 #endif
00332 }
00333
00334
00336 void KitListGui::run() {
00337 m_kit.run(*m_window);
00338 #ifdef MAEMO
00339 if (m_osso_context != NULL)
00340 osso_deinitialize(m_osso_context);
00341 #endif
00342 if (m_service.is_model_dirty()) {
00343 #ifdef MAEMO
00344
00345
00346
00347
00348 if (m_filename.length() > 0) {
00349 m_service.save_as_xml(m_filename);
00350 }
00351 #else
00352 g_warning("WARNING: Application is closing with unsaved changes");
00353 #endif //MAEMO
00354 }
00355 }
00356
00357
00358 gint KitListGui::get_max_recent_files() {
00359 gint retval = DEFAULT_MAX_RECENT_FILES;
00360 #ifdef MAEMO
00361 Gnome::Conf::Value value;
00362 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00363 value = m_ref_gconf_client->get_int(GCONF_KEY_MAX_RECENT_FILES);
00364 #else
00365 std::auto_ptr<Glib::Error> error;
00366 value = m_ref_gconf_client->get(GCONF_KEY_MAX_RECENT_FILES, error);
00367 if (error.get())
00368 g_warning(_("GConf error: %s"), error->what().c_str());
00369 #endif //GLIBMM_EXCEPTIONS_ENABLED
00370 if (value.get_type() == Gnome::Conf::VALUE_INT) {
00371 retval = value.get_int();
00372
00373
00374
00375
00376
00377
00378
00379
00380 }
00381 #endif
00382 return retval;
00383 }
00384
00385 #ifdef MAEMO
00387 bool KitListGui::on_window_state_event(GdkEventWindowState* event) {
00388 m_full_screen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
00389 }
00390
00391
00393 bool KitListGui::on_key_pressed(GdkEventKey* key) {
00394 if (key->keyval == GDK_F6) {
00395 if (!m_full_screen) {
00396 m_window->fullscreen();
00397 } else {
00398 m_window->unfullscreen();
00399 }
00400 return true;
00401 }
00402 return false ;
00403 };
00404
00405
00407 void KitListGui::show_banner(const Glib::ustring& msg) {
00408 Hildon::Banner::show_information(*m_window, msg);
00409 }
00410
00411 #endif
00412
00413
00415 bool KitListGui::confirm_lose_changes(const Glib::ustring& message) {
00416
00417 Gtk::MessageDialog dialog(*m_window,
00418 message,
00419 false,
00420 Gtk::MESSAGE_WARNING,
00421 Gtk::BUTTONS_NONE);
00422 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
00423 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_APPLY);
00424 dialog.add_button(_("_Discard Changes"), Gtk::RESPONSE_CLOSE);
00425 int result = dialog.run();
00426 switch (result) {
00427 case (Gtk::RESPONSE_CANCEL) :
00428 return false;
00429 case (Gtk::RESPONSE_APPLY) :
00430 #ifdef XML_DAO
00431 if (m_filename.length() > 0) {
00432 m_service.save_as_xml(m_filename);
00433 m_service.set_model_dirty(false);
00434 return true;
00435 }
00436 return false;
00437 #else
00438 m_service.save();
00439 m_service.set_model_dirty(false);
00440 return true;
00441 #endif
00442 case (Gtk::RESPONSE_CLOSE) :
00443 return true;
00444 default :
00445 return false;
00446 }
00447 }
00448
00449
00453 void KitListGui::update_recent_files_menu() {
00454 #ifdef GCONF
00455
00456 std::deque<Glib::ustring> mru =
00457 m_ref_gconf_client->get_string_list(GCONF_KEY_RECENT_FILES);
00458
00459 if (m_recent_files_menu_item) {
00460 if (m_recent_files_menu_item->has_submenu()) {
00461 m_recent_files_menu_item->remove_submenu();
00462 }
00463 Gtk::Menu* recent_menu = Gtk::manage(new Gtk::Menu);
00464
00465 m_recent_files_menu_item->set_submenu(*recent_menu);
00466 for (std::deque<Glib::ustring>::iterator i = mru.begin();
00467 i != mru.end();
00468 ++i) {
00469 Gtk::MenuItem* m = Gtk::manage(new Gtk::MenuItem(*i));
00470 m->signal_activate().connect(
00471 sigc::bind<Glib::ustring>(
00472 sigc::mem_fun(*this, &KitListGui::on_menu_recent_file), *i)
00473 );
00474 recent_menu->add(*m);
00475 recent_menu->show_all_children();
00476 }
00477 } else {
00478 g_warning("Couldn't find recent files menu item");
00479 }
00480 #endif // GCONF
00481 }
00482
00483
00490 void KitListGui::update_recent_files(const Glib::ustring& filename) {
00491 #ifdef GCONF
00492
00493
00494 std::deque<Glib::ustring> mru =
00495 m_ref_gconf_client->get_string_list(GCONF_KEY_RECENT_FILES);
00496
00497 for (std::deque<Glib::ustring>::iterator i = mru.begin(); i != mru.end(); ++i) {
00498 if (*i == filename) {
00499 mru.erase(i);
00500 break;
00501 }
00502 }
00503
00504 mru.push_front(filename);
00505 while (mru.size() > get_max_recent_files()) {
00506 mru.pop_back();
00507 }
00508
00509
00510 m_ref_gconf_client->set_string_list(GCONF_KEY_RECENT_FILES, mru);
00511
00512
00513 update_recent_files_menu();
00514 #endif // GCONF
00515 }
00516
00517
00519 bool KitListGui::on_delete_event(GdkEventAny* event) {
00520 if (m_service.is_model_dirty() &&
00521 !confirm_lose_changes(_("Your changes will be lost if you quit now"))) {
00522 return true;
00523 }
00524
00525
00526
00527 m_service.set_model_dirty(false);
00528 return false;
00529 }
00530
00531
00533 void KitListGui::on_menu_quit() {
00534 if (m_service.is_model_dirty() &&
00535 !confirm_lose_changes(_("Your changes will be lost if you quit now"))) {
00536 return;
00537 }
00538
00539
00540
00541 m_service.set_model_dirty(false);
00542 m_window->hide();
00543 }
00544
00545
00550 void KitListGui::on_menu_file_new() {
00551 if (m_status_bar)
00552 m_status_bar->pop(SB_SAVE);
00553 if (m_service.is_model_dirty() &&
00554 !confirm_lose_changes(_("Your changes will be lost if you continue"))) {
00555 return;
00556 }
00557 #ifndef TRANSITION_DAO
00558 if (m_service.require_filename()) {
00559 #endif
00560 m_filename.clear();
00561 #ifdef GCONF
00562 if (m_ref_gconf_client) {
00563 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00564 m_ref_gconf_client->unset(GCONF_KEY_CURRENT_FILENAME);
00565 #else
00566 std::auto_ptr<Glib::Error> error;
00567 m_ref_gconf_client->unset(GCONF_KEY_CURRENT_FILENAME, error);
00568 if (error.get())
00569 g_warning(_("GConf error: %s"), error->what().c_str());
00570 #endif //GLIBMM_EXCEPTIONS_ENABLED
00571 }
00572 #endif // GCONF
00573 m_service.create_default_model();
00574
00575
00576 refresh_category_list(-1);
00577 refresh_item_list();
00578 #ifndef TRANSITION_DAO
00579 } else {
00580 #ifdef MAEMO
00581 show_banner(_("New databases must be created manually"));
00582 #else
00583 if (m_status_bar)
00584 m_status_bar->push(_("New databases must be created manually"), SB_SAVE);
00585 #endif
00586 }
00587 #endif
00588 }
00589
00590
00597 void KitListGui::on_menu_file_open() {
00598 if (m_status_bar)
00599 m_status_bar->pop(SB_SAVE);
00600 if (m_service.is_model_dirty() &&
00601 !confirm_lose_changes(_("Your changes will be lost if you continue"))) {
00602 return;
00603 }
00604 #ifdef MAEMO
00605 Hildon::FileChooserDialog dialog(*m_window, Gtk::FILE_CHOOSER_ACTION_OPEN);
00606 #else
00607
00608 Gtk::FileChooserDialog dialog(_("Open File"), Gtk::FILE_CHOOSER_ACTION_OPEN);
00609 dialog.set_transient_for(*m_window);
00610
00611 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
00612 dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
00613 #endif
00614 Gtk::FileFilter filter_xml;
00615 filter_xml.set_name(_("Kit files"));
00616 #ifdef WIN32
00617 filter_xml.add_pattern("*" + DEFAULT_FILENAME_EXTENSION);
00618 #elif MAEMO
00619
00620
00621
00622 filter_xml.add_pattern("*" + DEFAULT_FILENAME_EXTENSION);
00623
00624 #else
00625 filter_xml.add_pattern("*" + DEFAULT_FILENAME_EXTENSION);
00626
00627 #endif
00628 dialog.add_filter(filter_xml);
00629
00630 Gtk::FileFilter filter_any;
00631 filter_any.set_name(_("Any files"));
00632 filter_any.add_pattern("*");
00633 dialog.add_filter(filter_any);
00634
00635 int result = dialog.run();
00636 dialog.hide();
00637 Glib::ustring filename;
00638 switch(result) {
00639 case(Gtk::RESPONSE_OK):
00640 filename = dialog.get_filename();
00641 break;
00642 case(Gtk::RESPONSE_CANCEL):
00643 return;
00644 default:
00645 return;
00646 }
00647 open_file(filename);
00648 }
00649
00650
00655 void KitListGui::open_file(const Glib::ustring& filename) {
00656 m_service.open_as_xml(filename);
00657 m_filename = filename;
00658 update_recent_files(m_filename);
00659
00660 #ifdef GCONF
00661 if (m_ref_gconf_client) {
00662 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00663 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME, m_filename);
00664 #else
00665 std::auto_ptr<Glib::Error> error;
00666 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME, m_filename, error);
00667 if (error.get())
00668 g_warning(_("GConf error: %s"), error->what().c_str());
00669 #endif //GLIBMM_EXCEPTIONS_ENABLED
00670 }
00671 #endif
00672
00673
00674
00675 refresh_category_list(-1);
00676 refresh_item_list();
00677 }
00678
00679
00686 void KitListGui::safe_open_file(const Glib::ustring& filename) {
00687 if (m_status_bar)
00688 m_status_bar->pop(SB_SAVE);
00689 if (m_service.is_model_dirty() &&
00690 !confirm_lose_changes(_("Your changes will be lost if you continue"))) {
00691 return;
00692 }
00693 open_file(filename);
00694 }
00695
00696
00700 void KitListGui::on_menu_save() {
00701 if (m_status_bar)
00702 m_status_bar->pop(SB_SAVE);
00703 if (m_service.is_model_dirty()) {
00704
00705
00706
00707
00708 if (m_service.require_filename() && m_filename.size() == 0) {
00709 on_menu_save_as();
00710 } else {
00711 Glib::ustring msg = _("Saving changes...");
00712 if (m_status_bar)
00713 m_status_bar->push(msg, SB_SAVE);
00714 #ifndef XML_DAO
00715 m_service.save();
00716 #else
00717 m_service.save_as_xml(m_filename);
00718 update_recent_files(m_filename);
00719 #ifdef GCONF
00720 if (m_ref_gconf_client) {
00721 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00722 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME,
00723 m_filename);
00724 #else
00725 std::auto_ptr<Glib::Error> error;
00726 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME, m_filename, error);
00727 if (error.get())
00728 g_warning(_("GConf error: %s"), error->what().c_str());
00729 #endif //GLIBMM_EXCEPTIONS_ENABLED
00730 }
00731 #endif // GCONF
00732 #endif // !XML_DAO
00733 if (m_status_bar)
00734 m_status_bar->pop(SB_SAVE);
00735 msg = _("Saved");
00736 if (m_status_bar)
00737 m_status_bar->push(msg, SB_SAVE);
00738 }
00739 } else {
00740 #ifdef MAEMO
00741 show_banner(_("Nothing to save"));
00742 #else
00743 if (m_status_bar)
00744 m_status_bar->push(Glib::ustring(_("Nothing to save")), SB_SAVE);
00745 #endif
00746 }
00747 }
00748
00749
00753 void KitListGui::on_menu_save_as() {
00754 if (m_status_bar) {
00755 m_status_bar->pop(SB_SAVE);
00756 m_status_bar->push(_("Choosing target filename"), SB_SAVE);
00757 }
00758 if (choose_filename(m_filename)) {
00759 if (m_status_bar) {
00760 m_status_bar->pop(SB_SAVE);
00761 m_status_bar->push(_("Saving..."), SB_SAVE);
00762 }
00763
00764 m_service.save_as_xml(m_filename);
00765 update_recent_files(m_filename);
00766
00767 if (m_status_bar) {
00768 m_status_bar->pop(SB_SAVE);
00769 m_status_bar->push(_("Saved"), SB_SAVE);
00770 }
00771 #ifdef GCONF
00772 if (m_ref_gconf_client) {
00773 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00774 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME, m_filename);
00775 #else
00776 std::auto_ptr<Glib::Error> error;
00777 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME, m_filename, error);
00778 if (error.get())
00779 g_warning(_("GConf error: %s"), error->what().c_str());
00780 #endif //GLIBMM_EXCEPTIONS_ENABLED
00781 }
00782 #endif // GCONF
00783 #ifdef MAEMO
00784 show_banner(_("Saved"));
00785 #endif
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796 } else {
00797 if (m_status_bar) {
00798 m_status_bar->pop(SB_SAVE);
00799 m_status_bar->push(_("Save cancelled"), SB_SAVE);
00800 }
00801 #ifdef MAEMO
00802 show_banner(_("Save cancelled"));
00803 #endif
00804 }
00805 }
00806
00807
00811 void KitListGui::on_printoperation_status_changed(const Glib::RefPtr<Gtk::PrintOperation>& op) {
00812 if (m_status_bar)
00813 m_status_bar->pop(SB_PRINT);
00814 Glib::ustring status_msg;
00815 if (op->is_finished())
00816 status_msg = _("Print job completed");
00817 else
00818 status_msg = op->get_status_string();
00819
00820 m_status_bar->push(status_msg, SB_PRINT);
00821 }
00822
00826 void KitListGui::on_printoperation_done(Gtk::PrintOperationResult result, const Glib::RefPtr<Gtk::PrintOperation>& op) {
00827 if (result == Gtk::PRINT_OPERATION_RESULT_ERROR) {
00828 Gtk::MessageDialog err_dialog(*this->m_window, _("Error printing list"), false,
00829 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
00830 err_dialog.run();
00831 } else if (result == Gtk::PRINT_OPERATION_RESULT_APPLY)
00832 m_ref_printer_settings = op->get_print_settings();;
00833 if (! op->is_finished())
00834 op->signal_status_changed().connect(sigc::bind(sigc::mem_fun(*this, &KitListGui::on_printoperation_status_changed), op));
00835 }
00836
00837
00841 void KitListGui::on_menu_print() {
00842 Glib::RefPtr<KitPrintOperation> op = KitPrintOperation::create();
00843 ItemContainer *items = m_service.get_filtered_items(get_selected_category());
00844 op->set_items(items);
00845 op->set_track_print_status();
00846 op->set_default_page_setup(m_ref_page_setup);
00847 op->set_print_settings(m_ref_printer_settings);
00848 op->set_page_title(m_page_title);
00849 op->signal_done().connect(sigc::bind(sigc::mem_fun(*this, &KitListGui::on_printoperation_done), op));
00850
00851 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00852 try {
00853 op->run();
00854 } catch (const Gtk::PrintError& ex) {
00855 g_error("An error occured while trying to run a print operation: %s", ex.what().c_str());
00856 }
00857 #else
00858 std::auto_ptr<Glib::Error> error;
00859 op->run(Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG, error);
00860 if (error.get())
00861 g_warning(_("Error running print job: %s"),
00862 error->what().c_str());
00863 #endif //GLIBMM_EXCEPTIONS_ENABLED
00864 }
00865
00866
00870 void KitListGui::on_menu_export_to_pdf() {
00871 if (m_status_bar) {
00872 m_status_bar->pop(SB_SAVE);
00873 m_status_bar->push(_("Choosing export filename"), SB_SAVE);
00874 }
00875 Glib::ustring pdf_filename;
00876 if (choose_pdf_filename(pdf_filename)) {
00877 if (m_status_bar) {
00878 m_status_bar->pop(SB_SAVE);
00879 m_status_bar->push(_("Exporting..."), SB_SAVE);
00880 }
00881 Glib::RefPtr<KitPrintOperation> op = KitPrintOperation::create();
00882 ItemContainer *items = m_service.get_filtered_items(get_selected_category());
00883 op->set_items(items);
00884 op->set_track_print_status();
00885 op->set_default_page_setup(m_ref_page_setup);
00886 op->set_print_settings(m_ref_printer_settings);
00887 op->set_page_title(m_page_title);
00888
00889 op->set_export_filename(pdf_filename);
00890
00891 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00892 try {
00893 op->run(Gtk::PRINT_OPERATION_ACTION_EXPORT);
00894 } catch (const Gtk::PrintError& ex) {
00895 g_error("An error occured while trying to run a print operation: %s", ex.what().c_str());
00896 }
00897 #else
00898 std::auto_ptr<Glib::Error> error;
00899 op->run(Gtk::PRINT_OPERATION_ACTION_EXPORT, error);
00900 if (error.get())
00901 g_warning(_("Error running print job: %s"),
00902 error->what().c_str());
00903 #endif //GLIBMM_EXCEPTIONS_ENABLED
00904
00905 if (m_status_bar) {
00906 m_status_bar->pop(SB_SAVE);
00907 m_status_bar->push(_("PDF exported"), SB_SAVE);
00908 }
00909 #ifdef MAEMO
00910 show_banner(_("PDF exported"));
00911 #endif
00912 } else {
00913 if (m_status_bar) {
00914 m_status_bar->pop(SB_SAVE);
00915 m_status_bar->push(_("Export cancelled"), SB_SAVE);
00916 }
00917 #ifdef MAEMO
00918 show_banner(_("Export cancelled"));
00919 #endif
00920 }
00921 }
00922
00926 void KitListGui::on_menu_recent_file(const Glib::ustring& filename) {
00927
00928 if (m_service.is_model_dirty() &&
00929 !confirm_lose_changes(_("Your changes will be lost if you continue"))) {
00930 return;
00931 }
00932 m_service.open_as_xml(filename);
00933 m_filename = filename;
00934 update_recent_files(m_filename);
00935
00936 #ifdef GCONF
00937 if (m_ref_gconf_client) {
00938 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00939 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME, m_filename);
00940 #else
00941 std::auto_ptr<Glib::Error> error;
00942 m_ref_gconf_client->set(GCONF_KEY_CURRENT_FILENAME, m_filename, error);
00943 if (error.get())
00944 g_warning(_("GConf error: %s"), error->what().c_str());
00945 #endif //GLIBMM_EXCEPTIONS_ENABLED
00946 }
00947 #endif // GCONF
00948
00949
00950
00951 refresh_category_list(-1);
00952 refresh_item_list();
00953 }
00954
00955
00959 ModelItemContainer* KitListGui::get_selected_items() {
00960 ModelItemContainer* retval = new ModelItemContainer;
00961 Glib::RefPtr<Gtk::TreeSelection> ref_tree_selection =
00962 m_item_tree_view->get_selection();
00963 if (ref_tree_selection) {
00964 if (ref_tree_selection->get_mode() == Gtk::SELECTION_MULTIPLE) {
00965 Gtk::TreeSelection::ListHandle_Path rows = ref_tree_selection->get_selected_rows();
00966 for (Glib::Container_Helpers::ListHandleIterator<Gtk::TreePath_Traits> path = rows.begin(); path != rows.end(); ++path) {
00967 Gtk::TreeModel::iterator iter = m_ref_item_tree_model->get_iter(*path);
00968 Gtk::TreeModel::Row row = *iter;
00969 int id = row[m_item_cols.m_col_num];
00970 ModelItem* item = m_service.find_item(id);
00971 if (item) {
00972 retval->push_back(item);
00973 } else {
00974 g_warning(_("Failed to find item to delete in model"));
00975 }
00976 }
00977 } else {
00978 Gtk::TreeModel::iterator iter = ref_tree_selection->get_selected();
00979 if (iter) {
00980 Gtk::TreeModel::Row row = *iter;
00981 int id = row[m_item_cols.m_col_num];
00982 ModelItem* item = m_service.find_item(id);
00983 if (item) {
00984 retval->push_back(item);
00985 } else {
00986 g_warning(_("Failed to find item to delete in model"));
00987 }
00988 } else {
00989 g_warning(_("Couldn't find the selected item or items"));
00990 }
00991 }
00992 } else {
00993 g_warning(_("Couldn't identify selection"));
00994 }
00995 return retval;
00996 }
00997
00998
01005 void KitListGui::delete_selected_items() {
01006 Glib::RefPtr<Gtk::TreeSelection> ref_tree_selection =
01007 m_item_tree_view->get_selection();
01008 if (ref_tree_selection) {
01009 if (ref_tree_selection->get_mode() == Gtk::SELECTION_MULTIPLE) {
01010 ref_tree_selection->selected_foreach_iter( sigc::mem_fun(*this, &KitListGui::selected_row_callback));
01011 refresh_item_list();
01012 } else {
01013 Gtk::TreeModel::iterator iter = ref_tree_selection->get_selected();
01014 if (iter) {
01015 Gtk::TreeModel::Row row = *iter;
01016 int id = row[m_item_cols.m_col_num];
01017 m_ref_item_tree_model->erase(iter);
01018 if (!m_service.delete_item(id))
01019 g_warning(_("Failed to find the item to delete in the model"));
01020 } else {
01021 g_warning(_("Couldn't find the selected item or items"));
01022 }
01023 }
01024 } else {
01025 g_warning(_("Couldn't identify selection"));
01026 }
01027 }
01028
01029
01037 void KitListGui::on_menu_delete() {
01038 Gtk::MessageDialog dialog(*m_window,
01039 _("Delete the selected items?"),
01040 false,
01041 Gtk::MESSAGE_QUESTION,
01042 Gtk::BUTTONS_YES_NO);
01043 int result = dialog.run();
01044 switch (result) {
01045 case (Gtk::RESPONSE_YES) :
01046 delete_selected_items();
01047 break;
01048 case (Gtk::RESPONSE_NO) :
01049 break;
01050 default:
01051 g_warning(_("Unexpected button"));
01052 break;
01053 }
01054 }
01055
01056
01060 ModelItemContainer* KitListGui::copy_selected_items_to_clipboard() {
01061 xmlpp::Document document;
01062 xmlpp::Element* nodeRoot = document.create_root_node("kitlist");
01063 assert(nodeRoot);
01064 nodeRoot->add_child_text("\n");
01065 ModelItemContainer* items = get_selected_items();
01066 for (ModelItemIter i = items->begin(); i != items->end(); ++i) {
01067 xmlpp::Element* nodeChild = nodeRoot->add_child("item");
01068 ostringstream os;
01069 os << (*i)->get_id();
01070 nodeChild->set_attribute(XML_ELEMENT_ID, os.str());
01071
01072 nodeChild->set_child_text((*i)->get_description());
01073 nodeRoot->add_child_text("\n");
01074 }
01075 m_clipboard_items = document.write_to_string();
01076
01077 Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
01078 std::list<Gtk::TargetEntry> listTargets;
01079 listTargets.push_back( Gtk::TargetEntry(item_target_custom) );
01080 listTargets.push_back( Gtk::TargetEntry(item_target_text) );
01081 refClipboard->set( listTargets,
01082 sigc::mem_fun(*this, &KitListGui::on_clipboard_get),
01083 sigc::mem_fun(*this, &KitListGui::on_clipboard_clear) );
01084 update_paste_status();
01085 return items;
01086 }
01087
01088
01093 void KitListGui::on_menu_cut() {
01094 long cat_id = get_selected_category();
01095 if (cat_id != -1) {
01096 ModelItemContainer* items = copy_selected_items_to_clipboard();
01097 if (items) {
01098 ModelCategory* category = m_service.find_category(cat_id);
01099 if (category) {
01100 m_service.set_model_dirty();
01101 category->remove_items(items);
01102 category->set_dirty(true);
01103 }
01104 refresh_item_list();
01105 }
01106 delete items;
01107 } else {
01108 if (m_status_bar) {
01109 m_status_bar->pop(SB_MSG);
01110 m_status_bar->push(_("Items can only be cut when a category is selected"), SB_MSG);
01111 }
01112 #ifdef MAEMO
01113 show_banner(_("Select a category before copying items"));
01114 #endif
01115 }
01116 }
01117
01118
01122 void KitListGui::on_menu_copy() {
01123 ModelItemContainer* items = copy_selected_items_to_clipboard();
01124 delete items;
01125 }
01126
01127
01131 void KitListGui::on_menu_paste() {
01132
01133 Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
01134 refClipboard->request_contents(item_target_text, sigc::mem_fun(
01135 *this,
01136 &KitListGui::on_clipboard_received) );
01137 paste_from_xml(m_clipboard_items);
01138 update_paste_status();
01139 }
01140
01141
01145 void KitListGui::on_menu_select_all() {
01146
01147 Glib::RefPtr<Gtk::TreeSelection> selection =
01148 m_item_tree_view->get_selection();
01149 if (selection)
01150 selection->select_all();
01151 m_item_tree_view->grab_focus();
01152 }
01153
01154
01156 void KitListGui::on_menu_create_category() {
01157 m_state = ADD_CATEGORY;
01158 m_current_cat_id = -1;
01159 #ifdef MAEMO
01160 Gtk::Dialog::Dialog dialog(_("Add Category"), *m_window, true, true);
01161
01162 Gtk::VBox* vbox = dialog.get_vbox();
01163
01164 Glib::RefPtr<Gtk::SizeGroup> group = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL);
01165 Gtk::Entry name;
01166
01167 Hildon::Caption* caption = Gtk::manage(new Hildon::Caption(
01168 _("Name"),
01169 name));
01170 vbox->pack_start(*caption);
01171
01172 dialog.set_size_request(500);
01173
01174 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01175 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
01176 dialog.show_all_children();
01177 int result = dialog.run();
01178 dialog.hide();
01179 switch (result) {
01180 case (Gtk::RESPONSE_CANCEL) :
01181 break;
01182 case (Gtk::RESPONSE_OK) :
01183
01184 Category* category = m_service.create_category();
01185
01186
01187
01188 if (category != NULL) {
01189 category->set_name(name.get_text());
01190 m_service.set_model_dirty();
01191 ((ModelCategory*) category)->set_dirty(true);
01192 refresh_category_list(category->get_id());
01193 refresh_item_list();
01194 }
01195 break;
01196 default :
01197 break;
01198 }
01199
01200
01201 #else
01202 if (m_window_add_category) {
01203 m_window_add_category->set_title(_("Add Category"));
01204 if (m_entry_add_category) {
01205 m_entry_add_category->set_text("");
01206 }
01207 m_entry_add_category->grab_focus();
01208 m_window_add_category->show();
01209 } else {
01210 g_warning(_("\"window_add_category\" resource is missing"));
01211 }
01212 #endif
01213 }
01214
01215
01226 void KitListGui::close_add_category_window() {
01227 m_window_add_category->hide();
01228 if (m_entry_add_category) {
01229 Category* category = NULL;
01230 if (m_state == ADD_CATEGORY) {
01231 category = m_service.create_category();
01232 } else {
01233 category = m_service.find_category(m_current_cat_id);
01234 }
01235 if (category != NULL) {
01236 category->set_name(m_entry_add_category->get_text());
01237 m_service.set_model_dirty();
01238 ((ModelCategory*) category)->set_dirty(true);
01239 refresh_category_list(category->get_id());
01240 refresh_item_list();
01241 }
01242 }
01243 }
01244
01245
01246
01251 void KitListGui::cancel_add_category_window() {
01252 m_window_add_category->hide();
01253 }
01254
01255
01262 void KitListGui::on_menu_delete_category() {
01263 long cat_id = get_selected_category();
01264 if (cat_id == -1) {
01265 if (m_status_bar) {
01266 m_status_bar->pop(SB_MSG);
01267 m_status_bar->push(_("No category selected"), SB_MSG);
01268 }
01269 #ifdef MAEMO
01270 show_banner(_("No category selected"));
01271 #endif
01272
01273 } else {
01274 Gtk::MessageDialog dialog(*m_window,
01275 _("Delete the current category?"),
01276 false,
01277 Gtk::MESSAGE_QUESTION,
01278 Gtk::BUTTONS_YES_NO);
01279 int result = dialog.run();
01280 switch (result) {
01281 case (Gtk::RESPONSE_YES) :
01282 m_service.delete_category(cat_id);
01283 refresh_category_list();
01284 refresh_item_list();
01285 break;
01286 case (Gtk::RESPONSE_NO) :
01287 break;
01288 default:
01289 g_warning(_("Unexpected button"));
01290 break;
01291 }
01292 }
01293 }
01294
01295
01299 void KitListGui::on_menu_rename_category() {
01300 m_state = RENAME_CATEGORY;
01301 m_current_cat_id = get_selected_category();
01302 #ifdef MAEMO
01303 if (m_current_cat_id != -1) {
01304
01305 ModelCategory* category = m_service.find_category(m_current_cat_id);
01306 if (category) {
01307
01308 Gtk::Dialog::Dialog dialog(_("Rename Category"), *m_window, true, true);
01309
01310 Gtk::VBox* vbox = dialog.get_vbox();
01311
01312 Glib::RefPtr<Gtk::SizeGroup> group = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL);
01313 Gtk::Entry name;
01314 name.set_text(category->get_name());
01315
01316 Hildon::Caption* caption = Gtk::manage(new Hildon::Caption(
01317 _("Name"),
01318 name));
01319 vbox->pack_start(*caption);
01320
01321 dialog.set_size_request(500);
01322
01323 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01324 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
01325 dialog.show_all_children();
01326 int result = dialog.run();
01327 dialog.hide();
01328 switch (result) {
01329 case (Gtk::RESPONSE_CANCEL) :
01330 break;
01331 case (Gtk::RESPONSE_OK) :
01332
01333
01334
01335
01336
01337
01338 category->set_name(name.get_text());
01339 m_service.set_model_dirty();
01340 ((ModelCategory*) category)->set_dirty(true);
01341 refresh_category_list(category->get_id());
01342 refresh_item_list();
01343
01344 break;
01345 default :
01346 break;
01347 }
01348 }
01349
01350 } else {
01351 show_banner(_("No category selected"));
01352 }
01353 #else
01354 if (m_window_add_category) {
01355 m_window_add_category->set_title(_("Rename Category"));
01356 if (m_current_cat_id != -1) {
01357 ModelCategory* category = m_service.find_category(m_current_cat_id);
01358 if (category != NULL && m_entry_add_category) {
01359 m_entry_add_category->set_text(category->get_name());
01360 }
01361 m_entry_add_category->grab_focus();
01362 m_window_add_category->show();
01363 } else {
01364 if (m_status_bar) {
01365 m_status_bar->pop(SB_MSG);
01366 m_status_bar->push(_("No category selected"), SB_MSG);
01367 }
01368 }
01369 } else {
01370 g_warning(_("\"window_add_category\" resource is missing"));
01371 }
01372 #endif
01373 }
01374
01375
01379 void KitListGui::on_menu_help_contents() {
01380
01381
01382
01383
01384 #ifdef MAEMO
01385 hildon_help_show(m_osso_context, "contents_kitlist_help", 0 );
01386 #endif
01387 }
01388
01389
01393 void KitListGui::on_menu_help_about() {
01394 Gtk::AboutDialog dialog;
01395 dialog.set_name(PACKAGE_NAME);
01396 dialog.set_copyright("(c) 2008-2009 Frank Dean");
01397 dialog.set_version(PACKAGE_VERSION);
01398 std::vector<Glib::ustring> authors;
01399 authors.push_back("frank.dean@smartpixie.com");
01400 dialog.set_authors(authors);
01401 dialog.run();
01402 }
01403
01404
01408 void KitListGui::set_selected(bool checked) {
01409 ModelItemContainer* items = get_selected_items();
01410 m_service.select_items(items, checked);
01411 refresh_item_list();
01412 delete items;
01413 }
01414
01415
01419 void KitListGui::toggle_selected() {
01420 ModelItemContainer* items = get_selected_items();
01421 m_service.toggle_selected_items(items);
01422 refresh_item_list();
01423 delete items;
01424 }
01425
01426
01430 void KitListGui::on_clipboard_get(Gtk::SelectionData& selection_data, guint) {
01431 const std::string target = selection_data.get_target();
01432
01433 if (target == item_target_custom) {
01434 selection_data.set_text(m_clipboard_items);
01435 } else if (target == item_target_text) {
01436 selection_data.set_text(m_clipboard_items);
01437 } else {
01438 g_warning("KitList::on_clipboard_get(): Unexpected clipboard target format");
01439 }
01440 }
01441
01442
01461 void KitListGui::on_clipboard_clear() {
01462 }
01463
01464
01472 void KitListGui::add_items(const ModelItemContainer& items) {
01473 long cat_id = get_selected_category();
01474 if (cat_id != -1) {
01475 m_service.copy_items(items, cat_id);
01476 refresh_item_list();
01477 }
01478 }
01479
01480
01484 void KitListGui::paste_from_xml(const Glib::ustring& document) {
01485 try {
01486 if (document.length() > 0) {
01487 xmlpp::DomParser parser;
01488 parser.set_substitute_entities();
01489 parser.parse_memory(document);
01490 const xmlpp::Node* nodeRoot = parser.get_document()->get_root_node();
01491 ModelItemContainer items;
01492 xmlpp::Node::NodeList nodes = nodeRoot->get_children();
01493 for (xmlpp::Node::NodeList::iterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
01494 const xmlpp::Node* node = (*iter);
01495
01496 const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node);
01497 if (nodeElement && node->get_name() == "item") {
01498 xmlpp::Attribute* attribute = nodeElement->get_attribute(XML_ELEMENT_ID);
01499 if (attribute) {
01500 Glib::ustring s = attribute->get_value();
01501 long id = atol(s.c_str());
01502 ModelItem* item = m_service.find_item(id);
01503 if (item) {
01504 items.push_back(item);
01505 }
01506 }
01507 }
01508 }
01509 add_items(items);
01510 }
01511 } catch (std::exception ex) {
01512 g_warning("Error pasting clipboard - perhaps it was empty");
01513 }
01514 }
01515
01516
01520 void KitListGui::on_clipboard_received(const Gtk::SelectionData& selection_data) {
01521 const std::string target = selection_data.get_target();
01522 Glib::ustring s;
01523 if (target == item_target_custom || target == item_target_text) {
01524 m_clipboard_items = selection_data.get_data_as_string();
01525 } else {
01526 g_warning("KitList::on_clipboard_get(): Unexpected clipboard target format");
01527 }
01528 }
01529
01530
01534 void KitListGui::update_item_count(size_t n) {
01535
01536 ostringstream os;
01537 os.imbue(std::locale(""));
01538 os << n << " " << (n == 1 ? _("item") : _("items"));
01539 if (m_status_bar) {
01540 m_status_bar->pop(SB_ITEM_COUNT);
01541 #ifdef GLIBMM_EXCEPTIONS_ENABLED
01542 m_status_bar->push(Glib::locale_to_utf8(os.str()), SB_ITEM_COUNT);
01543 #else
01544 std::auto_ptr<Glib::Error> ex;
01545 m_status_bar->push(Glib::locale_to_utf8(os.str(), ex), SB_ITEM_COUNT);
01546
01547 if (ex.get())
01548 g_warning(_("Error updating the status bar: %s"), ex->what().c_str());
01549 #endif // GLIBMM_EXCEPTIONS_ENABLED
01550 }
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562 }
01563
01564
01570 void KitListGui::on_cell_edit(const Glib::ustring s) {
01571 if (m_ignore_list_events)
01572 return;
01573 m_service.set_model_dirty(true);
01574 }
01575
01576
01587 bool KitListGui::choose_filename(Glib::ustring& filename) {
01588 bool retval = false;
01589 bool loop = true;
01590 while (loop) {
01591 #ifdef MAEMO
01592 Hildon::FileChooserDialog dialog(*m_window, Gtk::FILE_CHOOSER_ACTION_SAVE);
01593 #else
01594 Gtk::FileChooserDialog dialog(_("Save File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
01595 dialog.set_transient_for(*m_window);
01596
01597 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01598 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
01599 #endif
01600
01601 Gtk::FileFilter filter_xml;
01602 filter_xml.set_name(_("XML files"));
01603
01604 #ifdef WIN32
01605 filter_xml.add_pattern("*" + DEFAULT_FILENAME_EXTENSION);
01606 #elif MAEMO
01607 filter_xml.add_pattern("*" + DEFAULT_FILENAME_EXTENSION);
01608 #else
01609 filter_xml.add_pattern("*" + DEFAULT_FILENAME_EXTENSION);
01610
01611 #endif
01612
01613 dialog.add_filter(filter_xml);
01614
01615 Gtk::FileFilter filter_any;
01616 filter_any.set_name(_("Any files"));
01617 filter_any.add_pattern("*");
01618 dialog.add_filter(filter_any);
01619
01620 int result = dialog.run();
01621 dialog.hide();
01622
01623 switch(result) {
01624 case(Gtk::RESPONSE_OK):
01625 filename = dialog.get_filename();
01626 retval = true;
01627 break;
01628 case(Gtk::RESPONSE_CANCEL):
01629 break;
01630 default:
01631 break;
01632 }
01633 if (retval) {
01634
01635 Glib::ustring::size_type i = filename.find(".");
01636 if (i < 0 || i > filename.length()) {
01637 filename += DEFAULT_FILENAME_EXTENSION;
01638
01639 }
01640
01641 if (file_exists(filename)) {
01642 Gtk::MessageDialog dialog(*m_window,
01643 _("Overwrite existing file?"),
01644 false,
01645 Gtk::MESSAGE_WARNING,
01646 Gtk::BUTTONS_NONE);
01647 dialog.add_button(Gtk::Stock::NO, Gtk::RESPONSE_NO);
01648 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01649 dialog.add_button(Gtk::Stock::YES, Gtk::RESPONSE_YES);
01650 dialog.set_default_response(Gtk::RESPONSE_NO);
01651 int result = dialog.run();
01652 switch (result) {
01653 case (Gtk::RESPONSE_CANCEL) :
01654 retval = false;
01655 loop = false;
01656 break;
01657 case (Gtk::RESPONSE_NO) :
01658 retval = false;
01659 loop = true;
01660 break;
01661 case (Gtk::RESPONSE_YES) :
01662 loop = false;
01663 break;
01664 default :
01665 retval = false;
01666 loop = false;
01667 break;
01668 }
01669
01670 } else {
01671 loop = false;
01672 }
01673 } else {
01674 loop = false;
01675 }
01676 }
01677 return retval;
01678 }
01679
01680
01691 bool KitListGui::choose_pdf_filename(Glib::ustring& filename) {
01692 bool retval = false;
01693 bool loop = true;
01694 while (loop) {
01695 #ifdef MAEMO
01696 Hildon::FileChooserDialog dialog(*m_window, Gtk::FILE_CHOOSER_ACTION_SAVE);
01697 #else
01698 Gtk::FileChooserDialog dialog(_("Export to PDF"), Gtk::FILE_CHOOSER_ACTION_SAVE);
01699 dialog.set_transient_for(*m_window);
01700
01701 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01702 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
01703 #endif
01704
01705 Gtk::FileFilter filter_pdf;
01706 filter_pdf.set_name(_("PDF files"));
01707 filter_pdf.add_pattern("*" + PDF_FILENAME_EXTENSION);
01708 dialog.add_filter(filter_pdf);
01709
01710 Gtk::FileFilter filter_any;
01711 filter_any.set_name(_("Any files"));
01712 filter_any.add_pattern("*");
01713 dialog.add_filter(filter_any);
01714
01715 int result = dialog.run();
01716 dialog.hide();
01717
01718 switch(result) {
01719 case(Gtk::RESPONSE_OK):
01720 filename = dialog.get_filename();
01721 retval = true;
01722 break;
01723 case(Gtk::RESPONSE_CANCEL):
01724 break;
01725 default:
01726 break;
01727 }
01728 if (retval) {
01729
01730 Glib::ustring::size_type i = filename.find(".");
01731 if (i < 0 || i > filename.length()) {
01732 filename += PDF_FILENAME_EXTENSION;
01733
01734 }
01735
01736 if (file_exists(filename)) {
01737 Gtk::MessageDialog dialog(*m_window,
01738 _("Overwrite existing file?"),
01739 false,
01740 Gtk::MESSAGE_WARNING,
01741 Gtk::BUTTONS_NONE);
01742 dialog.add_button(Gtk::Stock::NO, Gtk::RESPONSE_NO);
01743 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01744 dialog.add_button(Gtk::Stock::YES, Gtk::RESPONSE_YES);
01745 dialog.set_default_response(Gtk::RESPONSE_NO);
01746 int result = dialog.run();
01747 switch (result) {
01748 case (Gtk::RESPONSE_CANCEL) :
01749 retval = false;
01750 loop = false;
01751 break;
01752 case (Gtk::RESPONSE_NO) :
01753 retval = false;
01754 loop = true;
01755 break;
01756 case (Gtk::RESPONSE_YES) :
01757 loop = false;
01758 break;
01759 default :
01760 retval = false;
01761 loop = false;
01762 break;
01763 }
01764
01765 } else {
01766 loop = false;
01767 }
01768 } else {
01769 loop = false;
01770 }
01771 }
01772 return retval;
01773 }
01774
01775
01779 void KitListGui::update_paste_status() {
01780 Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
01781 refClipboard->request_targets( sigc::mem_fun(*this, &KitListGui::paste_status_received) );
01782 }
01783
01784
01791 void KitListGui::paste_status_received(const Glib::StringArrayHandle& targets_array) {
01792 std::list<std::string> targets = targets_array;
01793 bool can_paste = false;
01794 for (std::list<std::string>::iterator i = targets.begin(); i != targets.end(); ++i) {
01795 if ( *i == item_target_custom || *i == item_target_text) {
01796 can_paste = true;
01797 break;
01798 }
01799 }
01800
01801 if (m_paste_menu_item)
01802 m_paste_menu_item->set_sensitive(can_paste);
01803
01804 if (m_paste_tool_button)
01805 m_paste_tool_button->set_sensitive(can_paste);
01806 }
01807
01808
01809
01818 void KitListGui::on_row_changed(const Gtk::TreeModel::Path path, const Gtk::TreeModel::iterator iter) {
01819 if (m_ignore_list_events)
01820 return;
01821 m_service.set_model_dirty(true);
01822 Gtk::TreeModel::Row row = *iter;
01823 int id = row[m_item_cols.m_col_num];
01824 Glib::ustring us = row[m_item_cols.m_col_text];
01825 string s(us);
01826 if (!m_service.update_item(id, s, row[m_item_cols.m_col_checked]))
01827 g_warning(_("Unable to find the item in the model: %d"), id);
01828 }
01829
01830
01834 void KitListGui::selected_row_callback(const Gtk::TreeModel::iterator& iter) {
01835 Gtk::TreeModel::Row row = *iter;
01836 int id = row[m_item_cols.m_col_num];
01837 if (!m_service.delete_item(id))
01838 g_warning(_("Failed to find item to delete in model"));
01839 }
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01864 void KitListGui::refresh_item_list() {
01865 m_ignore_list_events = true;
01866 int cat_id = get_selected_category();
01867
01868 m_ref_item_tree_model->clear();
01869 ItemContainer *items = m_service.get_items(cat_id);
01870 if (items)
01871 sort(items->begin(), items->end(), ItemCompareName());
01872
01873
01874 size_t count = 0;
01875 if (items && !items->empty()) {
01876 for (ItemIter i = items->begin(); i != items->end(); ++i) {
01877 if (m_service.filter((*i)->get_checked())) {
01878
01879 count++;
01880 Gtk::TreeModel::iterator item_iter = m_ref_item_tree_model->append();
01881 Gtk::TreeModel::Row row = *item_iter;
01882 row[m_item_cols.m_col_text] = (*i)->get_description();
01883 row[m_item_cols.m_col_num] = (*i)->get_id();
01884 row[m_item_cols.m_col_checked] = (*i)->get_checked();
01885 }
01886 }
01887 }
01888 if (items)
01889 delete items;
01890 update_item_count(count);
01891 m_ignore_list_events = false;
01892 }
01893
01894
01903 void KitListGui::refresh_category_list(long cat_id) {
01904 m_ignore_list_events = true;
01905
01906 if (cat_id == -2)
01907 cat_id = get_selected_category();
01908 CategoryContainer* c = m_service.get_categories();
01909 sort(c->begin(), c->end(), CategoryCompareName());
01910 m_ref_category_list_store->clear();
01911 Gtk::TreeModel::iterator iter = m_ref_category_list_store->append();
01912 Gtk::TreeModel::iterator active;
01913 Gtk::TreeModel::Row row = *iter;
01914 ostringstream os;
01915
01916 os.imbue(std::locale(""));
01917 #ifdef MAEMO
01918 os << "[" << _("All") << "]";
01919 #else
01920 os << "-- " << _("Show all items") << " --";
01921 #endif
01922 #ifdef GLIBMM_EXCEPTIONS_ENABLED
01923 row[m_category_cols.m_col_text] = Glib::locale_to_utf8(os.str());
01924 #else
01925 std::auto_ptr<Glib::Error> ex;
01926 row[m_category_cols.m_col_text] = Glib::locale_to_utf8(os.str(), ex);
01927 if (ex.get()) {
01928 g_warning("Failed to add item to category combo model: %s", ex->what().c_str());
01929 }
01930 #endif
01931 row[m_category_cols.m_col_num] = -1;
01932 if (!c->empty()) {
01933 for (CategoryIter i = c->begin(); i != c->end(); ++i) {
01934 ModelCategory* category = (ModelCategory*) *i;
01935 if ( !category->is_deleted() ) {
01936
01937 iter = m_ref_category_list_store->append();
01938 row = *iter;
01939 row[m_category_cols.m_col_text] = category->get_name();
01940 row[m_category_cols.m_col_num] = category->get_id();
01941 if (category->get_id() == cat_id)
01942 active = iter;
01943 }
01944 }
01945 }
01946 delete c;
01947 if (!active || cat_id == -1)
01948 m_category_combo->set_active(0);
01949 else
01950 m_category_combo->set_active(active);
01951 m_ignore_list_events = false;
01952 }
01953
01954
01958 void KitListGui::on_menu_preferences() {
01959 #ifdef MAEMO
01960 Gtk::Dialog::Dialog dialog(_("Preferences"), *m_window, true, true);
01961 Gtk::VBox* vbox = dialog.get_vbox();
01962
01963 Glib::RefPtr<Gtk::SizeGroup> group = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL);
01964 Gtk::Entry page_title;
01965 page_title.set_text(m_page_title);
01966
01967 Hildon::Caption* caption = Gtk::manage(new Hildon::Caption(
01968 _("Page Title"),
01969 page_title));
01970 vbox->pack_start(*caption);
01971
01972 dialog.set_size_request(500);
01973
01974 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01975 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
01976 dialog.show_all_children();
01977 int result = dialog.run();
01978 dialog.hide();
01979 switch (result) {
01980 case (Gtk::RESPONSE_CANCEL) :
01981 break;
01982 case (Gtk::RESPONSE_OK) :
01983 set_page_title(page_title.get_text());
01984 break;
01985 default :
01986 break;
01987 }
01988 #else
01989 if (m_window_preferences) {
01990 if (m_entry_page_title) {
01991 m_entry_page_title->set_text(m_page_title);
01992 m_entry_page_title->grab_focus();
01993 m_window_preferences->show();
01994 } else {
01995 g_warning(_("\"entry_page_title\" resource is missing"));
01996 }
01997 } else {
01998 g_warning(_("\"window_preferences\" resource is missing"));
01999 }
02000 #endif
02001 }
02002
02003
02004 void KitListGui::set_page_title(const Glib::ustring page_title) {
02005 m_page_title = page_title;
02006 #ifdef GCONF
02007 #ifdef GLIBMM_EXCEPTIONS_ENABLED
02008 m_ref_gconf_client->set(GCONF_KEY_PAGE_TITLE, m_page_title);
02009 #else
02010 std::auto_ptr<Glib::Error> error;
02011 m_ref_gconf_client->set(GCONF_KEY_PAGE_TITLE, m_page_title, error);
02012 if (error.get())
02013 g_warning(_("GConf error setting page title: %s"),
02014 error->what().c_str());
02015 #endif //GLIBMM_EXCEPTIONS_ENABLED
02016 #endif //GCONF
02017 }
02018
02023 void KitListGui::close_preferences_window() {
02024 set_page_title(m_entry_page_title->get_text());
02025 m_window_preferences->hide();
02026 }
02027
02028
02029 void KitListGui::cancel_preferences_window() {
02030 m_window_preferences->hide();
02031 }
02032
02033
02037 void KitListGui::on_menu_add() {
02038 #ifdef MAEMO
02039 Gtk::Dialog::Dialog dialog(_("Add Item"), *m_window, true, true);
02040
02041 Gtk::VBox* vbox = dialog.get_vbox();
02042
02043 Glib::RefPtr<Gtk::SizeGroup> group = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL);
02044 Gtk::Entry description;
02045
02046 Hildon::Caption* caption = Gtk::manage(new Hildon::Caption(
02047 _("Description"),
02048 description));
02049 vbox->pack_start(*caption);
02050 Gtk::CheckButton checkbutton(_("Chec_ked"), true);
02051 checkbutton.set_active(false);
02052 vbox->pack_start(checkbutton);
02053
02054 dialog.set_size_request(500);
02055
02056 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
02057 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
02058 dialog.show_all_children();
02059 int result = dialog.run();
02060 dialog.hide();
02061 switch (result) {
02062 case (Gtk::RESPONSE_CANCEL) :
02063 break;
02064 case (Gtk::RESPONSE_OK) :
02065
02066 long cat_id = get_selected_category();
02067 Item* item = m_service.create_item(cat_id);
02068 item->set_description(description.get_text());
02069 item->set_checked(checkbutton.get_active());
02070 refresh_item_list();
02071 break;
02072 default :
02073 break;
02074 }
02075
02076 #else
02077 if (m_window_add_item) {
02078 init_add_item_window();
02079 m_entry_add_item->grab_focus();
02080 m_window_add_item->show();
02081 } else {
02082 g_warning(_("\"window_add_item\" resource is missing"));
02083 }
02084 #endif
02085 }
02086
02087
02091 void KitListGui::init_add_item_window() {
02092 if (m_entry_add_item) {
02093 m_entry_add_item->set_text("");
02094 }
02095 }
02096
02097
02104 long KitListGui::get_selected_category() {
02105 long retval = -1;
02106 Gtk::TreeModel::iterator iter = m_category_combo->get_active();
02107 if (iter) {
02108 Gtk::TreeModel::Row row = *iter;
02109 if (row) {
02110 retval = row[m_category_cols.m_col_num];
02111 }
02112 }
02113 return retval;
02114 }
02115
02116
02121 void KitListGui::close_add_item_window() {
02122 m_window_add_item->hide();
02123
02124
02125 long cat_id = get_selected_category();
02126
02127 Item* item = m_service.create_item(cat_id);
02128 if (m_entry_add_item)
02129 item->set_description(m_entry_add_item->get_text());
02130 if (m_checkbutton_add_item)
02131 item->set_checked(m_checkbutton_add_item->get_active());
02132
02133 refresh_item_list();
02134 }
02135
02136
02141 void KitListGui::cancel_add_item_window() {
02142 m_window_add_item->hide();
02143 }
02144
02145
02149 void KitListGui::on_category_change() {
02150 if (m_ignore_list_events)
02151 return;
02152 refresh_item_list();
02153 }
02154
02155
02157 void KitListGui::raise() {
02158 m_window->present();
02159 }
02160
02161
02166 void KitListGui::init() {
02167
02168
02169 #ifdef XML_DAO
02170 Glib::ustring filename;
02171 #endif //XML_DAO
02172
02173 #ifdef KITLIST_DEBUG
02174 Glib::ustring log_filename;
02175 #endif //KITLIST_DEBUB
02176
02177 #ifdef GCONF
02178 #ifdef GLIBMM_EXCEPTIONS_ENABLED
02179 try {
02180 #endif //GLIBMM_EXCEPTIONS_ENABLED
02181 Gnome::Conf::init();
02182 m_ref_gconf_client = Gnome::Conf::Client::get_default_client();
02183
02184 #ifdef XML_DAO
02185 Gnome::Conf::Value value = Gnome::Conf::VALUE_INVALID;
02186 #ifdef GLIBMM_EXCEPTIONS_ENABLED
02187 m_ref_gconf_client->add_dir(GCONF_KEY);
02188 value = m_ref_gconf_client->get(GCONF_KEY_CURRENT_FILENAME);
02189 #else
02190 std::auto_ptr<Glib::Error> error;
02191 m_ref_gconf_client->add_dir(GCONF_KEY,
02192 Gnome::Conf::CLIENT_PRELOAD_NONE,
02193 error);
02194 if (error.get())
02195 g_warning(_("GConf error: %s"), error->what().c_str());
02196 value = m_ref_gconf_client->get(GCONF_KEY_CURRENT_FILENAME, error);
02197 if (error.get())
02198 g_warning(_("GConf error getting current filename: %s"),
02199 error->what().c_str());
02200 #endif //GLIBMM_EXCEPTIONS_ENABLED
02201 if (value.get_type() == Gnome::Conf::VALUE_STRING) {
02202 filename = value.to_string();
02203 }
02204 #endif //XML_DAO
02205
02206 #ifdef GLIBMM_EXCEPTIONS_ENABLED
02207 value = m_ref_gconf_client->get(GCONF_KEY_PAGE_TITLE);
02208 #else
02209 value = m_ref_gconf_client->get(GCONF_KEY_PAGE_TITLE, error);
02210 if (error.get())
02211 g_warning(_("GConf error getting page title: %s"),
02212 error->what().c_str());
02213 #endif // GLIBMM_EXCEPTIONS_ENABLED
02214 if (value.get_type() == Gnome::Conf::VALUE_STRING) {
02215 m_page_title = value.to_string();
02216 } else if (value.get_type() == Gnome::Conf::VALUE_INVALID) {
02217
02218 m_page_title = _("Kitlist");
02219 }
02220
02221
02222 #ifdef KITLIST_DEBUG
02223 #ifdef GLIBMM_EXCEPTIONS_ENABLED
02224 value = m_ref_gconf_client->get(GCONF_KEY_DEBUG_LOG);
02225 #else
02226 value = m_ref_gconf_client->get(GCONF_KEY_DEBUG_LOG, error);
02227 if (error.get())
02228 g_warning(_("GConf error getting log filename: %s"),
02229 error->what().c_str());
02230 #endif // GLIBMM_EXCEPTIONS_ENABLED
02231 if (value.get_type() == Gnome::Conf::VALUE_STRING) {
02232 log_filename = value.to_string();
02233 } else if (value.get_type() == Gnome::Conf::VALUE_INVALID) {
02234 log_filename = "/tmp/kitlist.log";
02235 #ifdef GLIBMM_EXCEPTIONS_ENABLED
02236 m_ref_gconf_client->set(GCONF_KEY_DEBUG_LOG, log_filename);
02237 #else
02238 std::auto_ptr<Glib::Error> error;
02239 m_ref_gconf_client->set(GCONF_KEY_DEBUG_LOG, log_filename, error);
02240 if (error.get())
02241 g_warning(_("GConf error setting log filename: %s"),
02242 error->what().c_str());
02243 #endif //GLIBMM_EXCEPTIONS_ENABLED
02244 }
02245 #endif //KITLIST_DEBUG
02246
02247 #ifdef GLIBMM_EXCEPTIONS_ENABLED
02248 } catch (const Glib::Error& ex) {
02249 g_warning(_("GConf error: %s"), ex.what().c_str());
02250 }
02251 #endif //GLIBMM_EXCEPTIONS_ENABLED
02252 #else // GCONF
02253
02254 m_page_title = _("Kitlist");
02255 #endif // GCONF
02256
02257 #ifdef KITLIST_DEBUG
02258 m_slog = new ofstream(log_filename.c_str(), ios_base::trunc);
02259 g_log_set_handler(NULL, (GLogLevelFlags) (G_LOG_LEVEL_MASK |
02260 G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
02261 my_log_handler, m_slog);
02262 #endif //KITLIST_DEBUG
02263
02264 #ifdef MAEMO
02265 Hildon::init();
02266 Hildon::fm_init();
02267 m_osso_context = osso_initialize(KITLIST_SERVICE_NAME, PACKAGE_VERSION, TRUE , NULL );
02268 if(!m_osso_context) {
02269 g_error("osso_initialize() failed.");
02270 }
02271
02272
02273
02274
02275
02276 osso_return_t result = osso_rpc_set_cb_f(m_osso_context,
02277 KITLIST_SERVICE_NAME,
02278 KITLIST_SERVICE_OBJECT,
02279 KITLIST_SERVICE_IFACE,
02280 dbus_req_handler,
02281 this);
02282 Glib::set_application_name(_("Kit List"));
02283 Gtk::Widget* container;
02284 Glib::RefPtr<Gnome::Glade::Xml> refXml = get_glade_ref_ptr(GLADE_APP_FILE);
02285 refXml->get_widget("main", container);
02286 m_window = new Hildon::Window;
02287 Hildon::Program::get_instance()->add_window(*m_window);
02288 m_window->add(*container);
02289
02290 m_window->signal_key_press_event().connect( sigc::mem_fun(*this, &KitListGui::on_key_pressed) );
02291 m_window->signal_window_state_event().connect( sigc::mem_fun(*this, &KitListGui::on_window_state_event) );
02292
02293 m_refActionGroup = Gtk::ActionGroup::create();
02294
02295
02296 m_refActionGroup->add(
02297 Gtk::Action::create("FileNewStandard", Gtk::Stock::NEW, _("New")),
02298 sigc::mem_fun(*this, &KitListGui::on_menu_file_new)
02299 );
02300
02301
02302 m_refActionGroup->add(
02303 Gtk::Action::create("FileOpenStandard", Gtk::Stock::OPEN, _("Open")),
02304 sigc::mem_fun(*this, &KitListGui::on_menu_file_open)
02305 );
02306
02307 m_refActionGroup->add(
02308 Gtk::Action::create("FileSaveStandard", Gtk::Stock::SAVE, _("Save")),
02309 sigc::mem_fun(*this, &KitListGui::on_menu_save)
02310 );
02311
02312 m_refActionGroup->add(
02313 Gtk::Action::create("FileSaveAsStandard", Gtk::Stock::SAVE_AS, _("Save As")),
02314 sigc::mem_fun(*this, &KitListGui::on_menu_save_as)
02315 );
02316
02317
02318
02319
02320
02321
02322
02323
02324 m_refActionGroup->add(Gtk::Action::create("FileRecent", _("Recent")));
02325
02326
02327 m_refActionGroup->add(
02328 Gtk::Action::create("EditSelectAll", Gtk::Stock::JUSTIFY_FILL, _("Select All")),
02329 sigc::mem_fun(*this, &KitListGui::on_menu_select_all)
02330 );
02331
02332
02333 m_refActionGroup->add(
02334 Gtk::Action::create("EditAdd", Gtk::Stock::ADD, _("Add")),
02335 sigc::mem_fun(*this, &KitListGui::on_menu_add)
02336 );
02337
02338
02339 m_refActionGroup->add(
02340 Gtk::Action::create("EditDelete", Gtk::Stock::DELETE, _("Delete")),
02341 sigc::mem_fun(*this, &KitListGui::on_menu_delete)
02342 );
02343
02344
02345 m_refActionGroup->add(
02346 Gtk::Action::create("EditCheckSelected", Gtk::Stock::APPLY, _("Check Selected")),
02347 sigc::mem_fun(*this, &KitListGui::on_menu_check_selected)
02348 );
02349
02350
02351 m_refActionGroup->add(
02352 Gtk::Action::create("EditUncheckSelected", Gtk::Stock::CLEAR, _("Uncheck Selected")),
02353 sigc::mem_fun(*this, &KitListGui::on_menu_uncheck_selected)
02354 );
02355
02356
02357 m_refActionGroup->add(
02358 Gtk::Action::create("EditToggleSelected", Gtk::Stock::CONVERT, _("Toggle Selected")),
02359 sigc::mem_fun(*this, &KitListGui::toggle_selected)
02360 );
02361
02362
02363 m_refActionGroup->add(
02364 Gtk::Action::create("EditCut", Gtk::Stock::CUT, _("Cut")),
02365 sigc::mem_fun(*this, &KitListGui::on_menu_cut)
02366 );
02367
02368
02369 m_refActionGroup->add(
02370 Gtk::Action::create("EditCopy", Gtk::Stock::COPY, _("Copy")),
02371 sigc::mem_fun(*this, &KitListGui::on_menu_copy)
02372 );
02373
02374
02375 m_refActionGroup->add(
02376 Gtk::Action::create("EditPaste", Gtk::Stock::PASTE, _("Paste")),
02377 sigc::mem_fun(*this, &KitListGui::on_menu_paste)
02378 );
02379
02380 m_refActionGroup->add(
02381 Gtk::Action::create("EditPreferences", Gtk::Stock::PREFERENCES, _("Preferences")),
02382 sigc::mem_fun(*this, &KitListGui::on_menu_preferences)
02383 );
02384
02385
02386 m_refActionGroup->add(
02387 Gtk::Action::create("ViewShowAll", Gtk::Stock::FIND, _("Show All")),
02388 sigc::mem_fun(*this, &KitListGui::on_menu_show_all)
02389 );
02390
02391
02392 m_refActionGroup->add(
02393 Gtk::Action::create("ViewShowChecked", Gtk::Stock::YES, _("Show Checked")),
02394 sigc::mem_fun(*this, &KitListGui::on_menu_show_checked)
02395 );
02396
02397
02398 m_refActionGroup->add(
02399 Gtk::Action::create("ViewShowUnchecked", Gtk::Stock::NO, _("Show Unchecked")),
02400 sigc::mem_fun(*this, &KitListGui::on_menu_show_unchecked)
02401 );
02402
02403
02404 m_refActionGroup->add(
02405 Gtk::Action::create("ViewRefresh", Gtk::Stock::REFRESH, _("Refresh")),
02406 sigc::mem_fun(*this, &KitListGui::refresh_item_list)
02407 );
02408
02409
02410 m_refActionGroup->add(
02411 Gtk::Action::create("CategoryAdd", Gtk::Stock::ADD, _("New")),
02412 sigc::mem_fun(*this, &KitListGui::on_menu_create_category)
02413 );
02414
02415
02416 m_refActionGroup->add(
02417 Gtk::Action::create("CategoryRename", Gtk::Stock::EDIT, _("Rename")),
02418 sigc::mem_fun(*this, &KitListGui::on_menu_rename_category)
02419 );
02420
02421
02422 m_refActionGroup->add(
02423 Gtk::Action::create("CategoryDelete", Gtk::Stock::DELETE, _("Delete")),
02424 sigc::mem_fun(*this, &KitListGui::on_menu_delete_category)
02425 );
02426
02427
02428 m_refActionGroup->add(
02429 Gtk::Action::create("HelpContents", Gtk::Stock::HELP, _("Help")),
02430 sigc::mem_fun(*this, &KitListGui::on_menu_help_contents)
02431 );
02432
02433
02434 m_refActionGroup->add(
02435 Gtk::Action::create("HelpAbout", Gtk::Stock::ABOUT, _("About")),
02436 sigc::mem_fun(*this, &KitListGui::on_menu_help_about)
02437 );
02438
02439
02440 m_refActionGroup->add( Gtk::Action::create("FileMenu", _("File")) );
02441 m_refActionGroup->add( Gtk::Action::create("FileNew", _("File")) );
02442 m_refActionGroup->add( Gtk::Action::create("EditMenu", _("Edit")) );
02443 m_refActionGroup->add( Gtk::Action::create("EditSubMenu", _("Edit")) );
02444 m_refActionGroup->add( Gtk::Action::create("ViewMenu", _("View")) );
02445 m_refActionGroup->add( Gtk::Action::create("ViewSubMenu", _("View")) );
02446 m_refActionGroup->add( Gtk::Action::create("CategoryMenu", _("Category")) );
02447 m_refActionGroup->add( Gtk::Action::create("CategorySubMenu", _("Category")) );
02448 m_refActionGroup->add( Gtk::Action::create("HelpMenu", _("Help")) );
02449 m_refActionGroup->add( Gtk::Action::create("HelpSubMenu", _("Help")) );
02450 m_refActionGroup->add(
02451 Gtk::Action::create("FileQuit", _("Close")),
02452 sigc::mem_fun(*this, &KitListGui::on_menu_quit)
02453 );
02454 m_refUIManager = Gtk::UIManager::create();
02455 m_refUIManager->insert_action_group(m_refActionGroup);
02456
02457 m_window->add_accel_group(m_refUIManager->get_accel_group());
02458
02459 Glib::ustring ui_info =
02460 "<ui>"
02461 " <popup action='FileMenu'>"
02462 " <menu action='FileNew'>"
02463 " <menuitem action='FileNewStandard'/>"
02464 " <menuitem action='FileOpenStandard'/>"
02465 " <menuitem action='FileSaveStandard'/>"
02466 " <menuitem action='FileSaveAsStandard'/>"
02467
02468
02469 " <menuitem action='FileRecent'/>"
02470 " </menu>"
02471 " <menu action='EditSubMenu'>"
02472 " <menuitem action='EditSelectAll'/>"
02473 " <menuitem action='EditAdd'/>"
02474 " <menuitem action='EditDelete'/>"
02475 " <separator/>"
02476 " <menuitem action='EditCheckSelected'/>"
02477 " <menuitem action='EditUncheckSelected'/>"
02478 " <menuitem action='EditToggleSelected'/>"
02479 " <separator/>"
02480 " <menuitem action='EditCut'/>"
02481 " <menuitem action='EditCopy'/>"
02482 " <menuitem action='EditPaste'/>"
02483 " <separator/>"
02484 " <menuitem action='EditPreferences'/>"
02485 " </menu>"
02486 " <menu action='ViewSubMenu'>"
02487 " <menuitem action='ViewShowAll'/>"
02488 " <menuitem action='ViewShowChecked'/>"
02489 " <menuitem action='ViewShowUnchecked'/>"
02490 " <separator/>"
02491 " <menuitem action='ViewRefresh'/>"
02492 " </menu>"
02493 " <menu action='CategorySubMenu'>"
02494 " <menuitem action='CategoryAdd'/>"
02495 " <menuitem action='CategoryRename'/>"
02496 " <menuitem action='CategoryDelete'/>"
02497 " </menu>"
02498 " <menu action='HelpSubMenu'>"
02499 " <menuitem action='HelpContents'/>"
02500 " <menuitem action='HelpAbout'/>"
02501 " </menu>"
02502 " <menuitem action='FileQuit'/>"
02503 " </popup>"
02504 " <toolbar name='ToolBar'>"
02505
02506
02507
02508
02509 " <toolitem action='EditAdd'/>"
02510
02511
02512 " <toolitem action='EditSelectAll'/>"
02513 " <toolitem action='EditCut'/>"
02514 " <toolitem action='EditCopy'/>"
02515 " <toolitem action='EditPaste'/>"
02516 " <toolitem action='EditCheckSelected'/>"
02517 " <toolitem action='EditUncheckSelected'/>"
02518 " <toolitem action='EditToggleSelected'/>"
02519 " <toolitem action='ViewShowAll'/>"
02520 " <toolitem action='ViewShowChecked'/>"
02521 " <toolitem action='ViewShowUnchecked'/>"
02522 " <toolitem action='ViewRefresh'/>"
02523
02524
02525 " </toolbar>"
02526 "</ui>";
02527
02528 std::auto_ptr<Glib::Error> ex;
02529 m_refUIManager->add_ui_from_string(ui_info, ex);
02530 if (ex.get()) {
02531 g_warning("building menus failed: %s", ex->what().c_str());
02532 }
02533 Gtk::Menu* pMenu = dynamic_cast<Gtk::Menu*>(m_refUIManager->get_widget("/FileMenu"));
02534 if (pMenu) {
02535 m_window->set_main_menu(*pMenu);
02536 }
02537
02538 m_recent_files_menu_item = dynamic_cast<Gtk::MenuItem*>(m_refUIManager->get_widget("/FileMenu/FileNew/FileRecent"));
02539
02540 m_paste_menu_item = dynamic_cast<Gtk::ImageMenuItem*>(m_refUIManager->get_widget("/FileMenu/EditSubMenu/EditPaste"));
02541 if (m_paste_menu_item)
02542 m_paste_menu_item->set_sensitive(false);
02543
02544 m_paste_tool_button = dynamic_cast<Gtk::ToolButton*>(m_refUIManager->get_widget("/ToolBar/EditPaste"));
02545 if (m_paste_tool_button)
02546 m_paste_tool_button->set_sensitive(false);
02547
02548 Gtk::Toolbar* pToolbar = dynamic_cast<Gtk::Toolbar*>(m_refUIManager->get_widget("/ToolBar"));
02549 if(pToolbar)
02550 m_window->add_toolbar(*pToolbar);
02551
02552
02553
02554
02555
02556 refXml->get_widget("window_add_item", m_window_add_item);
02557 if (m_window_add_item == NULL) {
02558 g_warning("Cannot find window_add_item");
02559 }
02560
02561
02562 #else
02563 Glib::RefPtr<Gnome::Glade::Xml> refXml = get_glade_ref_ptr(GLADE_APP_FILE);
02564 refXml->get_widget("main", m_window);
02565 refXml->get_widget("statusbar", m_status_bar);
02566 #endif // MAEMO
02567 refXml->get_widget("window_preferences", m_window_preferences);
02568 refXml->get_widget("entry_page_title", m_entry_page_title);
02569 refXml->get_widget("window_add_item", m_window_add_item);
02570 refXml->get_widget("window_add_category", m_window_add_category);
02571 m_window->signal_delete_event().connect( sigc::mem_fun(*this, &KitListGui::on_delete_event) );
02572
02573 #ifndef MAEMO
02574
02575 Gtk::MenuItem* p_menu_item = 0;
02576 refXml->get_widget("menu_file_quit", p_menu_item);
02577 if (p_menu_item)
02578 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_quit) );
02579 Gtk::ToolButton* p_tool_button = 0;
02580 refXml->get_widget("tool_button_quit", p_tool_button);
02581 if (p_tool_button)
02582 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_quit) );
02583
02584
02585 p_menu_item = 0;
02586 refXml->get_widget("menu_preferences", p_menu_item);
02587 if (p_menu_item)
02588 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_preferences) );
02589
02590
02591 p_menu_item = 0;
02592 refXml->get_widget("menu_delete_item", p_menu_item);
02593 if (p_menu_item)
02594 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_delete) );
02595 p_tool_button = 0;
02596 refXml->get_widget("tool_button_delete", p_tool_button);
02597 if (p_tool_button)
02598 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_delete) );
02599
02600
02601 p_menu_item = 0;
02602 refXml->get_widget("menu_add_item", p_menu_item);
02603 if (p_menu_item)
02604 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_add) );
02605 p_tool_button = 0;
02606 refXml->get_widget("tool_button_add", p_tool_button);
02607 if (p_tool_button)
02608 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_add) );
02609 #endif
02610 Gtk::Button* p_button = 0;
02611 refXml->get_widget("preferences_ok_button", p_button);
02612 if (p_button)
02613 p_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::close_preferences_window) );
02614 refXml->get_widget("preferences_cancel_button", p_button);
02615 if (p_button)
02616 p_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::cancel_preferences_window) );
02617 refXml->get_widget("add_item_ok_button", p_button);
02618 if (p_button)
02619 p_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::close_add_item_window) );
02620 p_button = 0;
02621 refXml->get_widget("add_item_cancel_button", p_button);
02622 if (p_button)
02623 p_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::cancel_add_item_window) );
02624 refXml->get_widget("entry_item_desc", m_entry_add_item);
02625 assert(m_entry_add_item);
02626 refXml->get_widget("item_checkbutton", m_checkbutton_add_item);
02627 assert(m_checkbutton_add_item);
02628
02629 #ifndef MAEMO
02630
02631 p_menu_item = 0;
02632 refXml->get_widget("menu_new", p_menu_item);
02633 if (p_menu_item) {
02634 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_file_new) );
02635 p_menu_item->set_sensitive(m_service.require_filename());
02636 }
02637 p_tool_button = 0;
02638 refXml->get_widget("tool_button_new", p_tool_button);
02639 if (p_tool_button) {
02640 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_file_new) );
02641 p_tool_button->set_sensitive(m_service.require_filename());
02642 }
02643
02644
02645 p_menu_item = 0;
02646 refXml->get_widget("menu_open", p_menu_item);
02647 if (p_menu_item) {
02648 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_file_open) );
02649 p_menu_item->set_sensitive(m_service.require_filename());
02650 }
02651 p_tool_button = 0;
02652 refXml->get_widget("tool_button_open", p_tool_button);
02653 if (p_tool_button) {
02654 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_file_open) );
02655 p_tool_button->set_sensitive(m_service.require_filename());
02656 }
02657
02658
02659 refXml->get_widget("menu_save", m_file_save_menu_item);
02660 if (m_file_save_menu_item)
02661 m_file_save_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_save) );
02662 refXml->get_widget("tool_button_save", m_file_save_tool_button);
02663 if (m_file_save_tool_button) {
02664 m_file_save_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_save) );
02665 }
02666
02667
02668 p_menu_item = 0;
02669 refXml->get_widget("menu_save_as", p_menu_item);
02670 if (p_menu_item) {
02671 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_save_as) );
02672 #ifdef TRANSITION_DAO
02673 p_menu_item->set_sensitive(true);
02674 #else
02675 p_menu_item->set_sensitive(m_service.require_filename());
02676 #endif
02677 }
02678
02679
02680 p_menu_item = 0;
02681 refXml->get_widget("menu_print", p_menu_item);
02682 if (p_menu_item)
02683 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_print) );
02684 p_tool_button = 0;
02685 refXml->get_widget("tool_button_print", p_tool_button);
02686 if (p_tool_button)
02687 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_print) );
02688
02689 p_menu_item = 0;
02690 refXml->get_widget("menu_export_pdf", p_menu_item);
02691 if (p_menu_item)
02692 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_export_to_pdf) );
02693
02694
02695 refXml->get_widget("menu_recent", m_recent_files_menu_item);
02696
02697
02698 p_menu_item = 0;
02699 refXml->get_widget("menu_cut", p_menu_item);
02700 if (p_menu_item)
02701 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_cut) );
02702 p_tool_button = 0;
02703 refXml->get_widget("tool_button_cut", p_tool_button);
02704 if (p_tool_button)
02705 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_cut) );
02706
02707
02708 p_menu_item = 0;
02709 refXml->get_widget("menu_copy", p_menu_item);
02710 if (p_menu_item)
02711 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_copy) );
02712 p_tool_button = 0;
02713 refXml->get_widget("tool_button_copy", p_tool_button);
02714 if (p_tool_button)
02715 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_copy) );
02716
02717
02718 refXml->get_widget("menu_paste", m_paste_menu_item);
02719 if (m_paste_menu_item)
02720 m_paste_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_paste) );
02721 refXml->get_widget("tool_button_paste", m_paste_tool_button);
02722 if (m_paste_tool_button)
02723 m_paste_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_paste) );
02724
02725
02726 p_menu_item = 0;
02727 refXml->get_widget("show_all", p_menu_item);
02728 if (p_menu_item)
02729 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_show_all) );
02730 p_tool_button = 0;
02731 refXml->get_widget("tool_button_show_all", p_tool_button);
02732 if (p_tool_button)
02733 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_show_all) );
02734
02735
02736 p_menu_item = 0;
02737 refXml->get_widget("show_checked", p_menu_item);
02738 if (p_menu_item)
02739 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_show_checked) );
02740 p_tool_button = 0;
02741 refXml->get_widget("tool_button_show_checked", p_tool_button);
02742 if (p_tool_button)
02743 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_show_checked) );
02744
02745
02746 p_menu_item = 0;
02747 refXml->get_widget("show_unchecked", p_menu_item);
02748 if (p_menu_item)
02749 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_show_unchecked) );
02750 p_tool_button = 0;
02751 refXml->get_widget("tool_button_show_unchecked", p_tool_button);
02752 if (p_tool_button)
02753 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_show_unchecked) );
02754
02755
02756 p_menu_item = 0;
02757 refXml->get_widget("refresh_view", p_menu_item);
02758 if (p_menu_item)
02759 p_menu_item->signal_activate().connect ( sigc::mem_fun(*this, &KitListGui::refresh_item_list) );
02760 p_tool_button = 0;
02761 refXml->get_widget("tool_button_refresh", p_tool_button);
02762 if (p_tool_button)
02763 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::refresh_item_list) );
02764
02765
02766 p_menu_item = 0;
02767 refXml->get_widget("select_all", p_menu_item);
02768 if (p_menu_item)
02769 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_select_all) );
02770 p_tool_button = 0;
02771 refXml->get_widget("tool_button_select_all", p_tool_button);
02772 if (p_tool_button)
02773 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_select_all) );
02774
02775
02776 p_menu_item = 0;
02777 refXml->get_widget("check_selected", p_menu_item);
02778 if (p_menu_item)
02779 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_check_selected) );
02780 p_tool_button = 0;
02781 refXml->get_widget("tool_button_check_selected", p_tool_button);
02782 if (p_tool_button)
02783 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_check_selected) );
02784
02785
02786 p_menu_item = 0;
02787 refXml->get_widget("uncheck_selected", p_menu_item);
02788 if (p_menu_item)
02789 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_uncheck_selected) );
02790 p_tool_button = 0;
02791 refXml->get_widget("tool_button_uncheck_selected", p_tool_button);
02792 if (p_tool_button)
02793 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::on_menu_uncheck_selected) );
02794
02795
02796 p_menu_item = 0;
02797 refXml->get_widget("toggle_selected", p_menu_item);
02798 if (p_menu_item)
02799 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::toggle_selected) );
02800 p_tool_button = 0;
02801 refXml->get_widget("tool_button_toggle_selected", p_tool_button);
02802 if (p_tool_button)
02803 p_tool_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::toggle_selected) );
02804
02805
02806 p_menu_item = 0;
02807 refXml->get_widget("create_category", p_menu_item);
02808 if (p_menu_item)
02809 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_create_category) );
02810 #endif // ifndef MAEMO
02811
02812 #ifdef XML_DAO
02813 update_recent_files_menu();
02814 #else
02815 m_recent_files_menu_item->set_sensitive(false);
02816 #endif
02817
02818 p_button = 0;
02819 refXml->get_widget("add_category_ok_button", p_button);
02820 if (p_button)
02821 p_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::close_add_category_window) );
02822 p_button = 0;
02823 refXml->get_widget("add_category_cancel_button", p_button);
02824 if (p_button)
02825 p_button->signal_clicked().connect( sigc::mem_fun(*this, &KitListGui::cancel_add_category_window) );
02826 refXml->get_widget("entry_category_name", m_entry_add_category);
02827 assert(m_entry_add_category);
02828
02829 #ifndef MAEMO
02830
02831 p_menu_item = 0;
02832 refXml->get_widget("delete_category", p_menu_item);
02833 if (p_menu_item)
02834 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_delete_category) );
02835
02836
02837 p_menu_item = 0;
02838 refXml->get_widget("rename_category", p_menu_item);
02839 if (p_menu_item)
02840 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_rename_category) );
02841
02842
02843 p_menu_item = 0;
02844 refXml->get_widget("help_about", p_menu_item);
02845 if (p_menu_item)
02846 p_menu_item->signal_activate().connect( sigc::mem_fun(*this, &KitListGui::on_menu_help_about) );
02847 #endif
02848
02849 m_ref_category_list_store = Gtk::ListStore::create(m_category_cols);
02850 #ifdef MAEMO
02851
02852
02853 Gtk::ToolItem* ti = new Gtk::ToolItem;
02854 m_category_combo = new Gtk::ComboBox(m_ref_category_list_store);
02855 m_category_combo->pack_start(m_category_cols.m_col_text);
02856 m_category_combo->set_column_span_column(1);
02857 ti->add(*m_category_combo);
02858 ti->set_expand();
02859 m_category_combo->set_size_request(40, 10);
02860 pToolbar->append(*ti);
02861 pToolbar->show_all();
02862 #else
02863
02864 refXml->get_widget("categoryCombo", m_category_combo);
02865 m_category_combo->set_model(m_ref_category_list_store);
02866 #endif
02867 refresh_category_list();
02868 m_category_combo->signal_changed().connect( sigc::mem_fun(*this, &KitListGui::on_category_change) );
02869
02870
02871 m_ref_item_tree_model = Gtk::ListStore::create(m_item_cols);
02872 refXml->get_widget("item_treeview", m_item_tree_view);
02873
02874 m_item_tree_view->set_model(m_ref_item_tree_model);
02875 ItemContainer* items = m_service.get_items();
02876 if (!items->empty()) {
02877 sort(items->begin(), items->end(), ItemCompareName());
02878 for (ItemIter i = items->begin(); i != items->end(); ++i) {
02879
02880 Gtk::TreeModel::iterator itemIter = m_ref_item_tree_model->append();
02881 Gtk::TreeModel::Row row = *itemIter;
02882 row[m_item_cols.m_col_text] = (*i)->get_description();
02883 row[m_item_cols.m_col_num] = (*i)->get_id();
02884 row[m_item_cols.m_col_checked] = (*i)->get_checked();
02885 }
02886 }
02887 m_ref_item_tree_model->signal_row_changed().connect( sigc::mem_fun(*this, &KitListGui::on_row_changed) );
02888
02889 update_item_count(items->size());
02890 delete items;
02891
02892 m_item_tree_view->append_column_editable(_("Checked"), m_item_cols.m_col_checked);
02893
02894 m_item_tree_view->append_column_editable(_("Item"), m_item_cols.m_col_text);
02895 #ifdef MAEMO
02896 m_item_tree_view->set_headers_visible(false);
02897 #endif
02898
02899
02900
02901
02902
02903
02904
02905 Glib::RefPtr<Gtk::TreeSelection> ref_tree_selection =
02906 m_item_tree_view->get_selection();
02907 ref_tree_selection->set_mode(Gtk::SELECTION_MULTIPLE);
02908 m_ignore_list_events = false;
02909 m_service.set_model_dirty(false);
02910 #ifdef XML_DAO
02911 if (filename.length() == 0 || !file_exists(filename)) {
02912
02913 filename = Glib::build_filename(
02914 Glib::get_home_dir(),
02915 DEFAULT_FILENAME);
02916
02917 m_filename = filename;
02918 }
02919 if (filename.length() > 0 && file_exists(filename)) {
02920
02921 m_filename = filename;
02922 m_service.open_as_xml(m_filename);
02923 refresh_category_list(-1);
02924 refresh_item_list();
02925 }
02926 #endif
02927 }