29 #include <glibmm/i18n.h> 30 #include <glibmm/refptr.h> 31 #include <glibmm/ustring.h> 32 #include <gtkmm/aboutdialog.h> 33 #include <gtkmm/cellrenderertoggle.h> 34 #include <gtkmm/clipboard.h> 35 #include <gtkmm/filechooserdialog.h> 36 #include <gtkmm/menuitem.h> 37 #include <gtkmm/messagedialog.h> 38 #include <gtkmm/stock.h> 39 #include <gtkmm/targetentry.h> 40 #include <gtkmm/window.h> 41 #include <libglademm/xml.h> 42 #include <libxml++/libxml++.h> 96 const Glib::ustring GCONF_KEY_DEBUG_LOG = GCONF_KEY +
"/debug_log_filename";
111 void my_log_handler(
const gchar *log_domain,
112 GLogLevelFlags log_level,
113 const gchar *message,
115 g_print(
"KITLIST: %s\n", message);
116 ofstream* fout = (ofstream*) data;
118 *fout << message << endl;
136 struct stat fileinfo;
138 retval = !(stat(filename.c_str(), &fileinfo));
147 locs.push_back(filename);
148 locs.push_back(
"../" + filename);
149 locs.push_back(
"./src/" + filename);
150 locs.push_back(
string(PACKAGE_DATA_DIR) +
"/glade/" + filename);
151 for (std::vector<string>::iterator i = locs.begin(); i != locs.end(); ++i) {
165 const Glib::ustring& root = Glib::ustring(),
166 const Glib::ustring& domain = Glib::ustring()) {
167 Glib::RefPtr<Gnome::Glade::Xml> refXml;
169 #ifdef GLIBMM_EXCEPTIONS_ENABLED 172 std::auto_ptr<Gnome::Glade::XmlError> ex;
175 g_error(_(
"Error loading Glade file: %s"), ex->what().c_str());
177 }
catch (
const Gnome::Glade::XmlError& ex) {
178 g_error(_(
"Error loading Glade file: %s"), ex.what().c_str());
195 m_ignore_list_events(false),
197 m_window_preferences(0),
198 m_entry_page_title(0),
199 m_window_add_item(0),
200 m_window_add_category(0),
202 m_entry_add_category(0),
203 m_file_save_menu_item(0),
204 m_file_save_tool_button(0),
205 m_paste_menu_item(0),
206 m_paste_tool_button(0),
207 m_checkbutton_add_item(0),
210 m_ref_item_tree_model(0),
214 m_current_cat_id(-1) {
235 g_warning(
"WARNING: Application is closing with unsaved changes");
249 Gtk::MessageDialog dialog(*
m_window,
252 Gtk::MESSAGE_WARNING,
254 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
255 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_APPLY);
256 dialog.add_button(_(
"_Discard Changes"), Gtk::RESPONSE_CLOSE);
257 int result = dialog.run();
259 case (Gtk::RESPONSE_CANCEL) :
261 case (Gtk::RESPONSE_APPLY) :
274 case (Gtk::RESPONSE_CLOSE) :
288 std::deque<Glib::ustring> mru =
298 Gtk::Menu* recent_menu = Gtk::manage(
new Gtk::Menu);
301 for (std::deque<Glib::ustring>::iterator i = mru.begin();
304 Gtk::MenuItem* m = Gtk::manage(
new Gtk::MenuItem(*i));
305 m->signal_activate().connect(
306 sigc::bind<Glib::ustring>(
309 recent_menu->add(*m);
310 recent_menu->show_all_children();
313 g_warning(
"Couldn't find recent files menu item");
328 std::deque<Glib::ustring> mru =
331 for (std::deque<Glib::ustring>::iterator i = mru.begin(); i != mru.end(); ++i) {
332 if (*i == filename) {
338 mru.push_front(filename);
394 #ifndef TRANSITION_DAO 399 if (m_ref_gconf_client) {
400 #ifdef GLIBMM_EXCEPTIONS_ENABLED 403 std::auto_ptr<Glib::Error> error;
406 g_warning(
"GConf error: %s", error->what().c_str());
407 #endif //GLIBMM_EXCEPTIONS_ENABLED 417 #ifndef TRANSITION_DAO 440 Gtk::FileChooserDialog dialog(_(
"Open File"), Gtk::FILE_CHOOSER_ACTION_OPEN);
441 dialog.set_transient_for(*
m_window);
443 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
444 dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
446 Gtk::FileFilter filter_xml;
447 filter_xml.set_name(_(
"Kit files"));
454 dialog.add_filter(filter_xml);
456 Gtk::FileFilter filter_any;
457 filter_any.set_name(_(
"Any files"));
458 filter_any.add_pattern(
"*");
459 dialog.add_filter(filter_any);
461 int result = dialog.run();
463 Glib::ustring filename;
465 case(Gtk::RESPONSE_OK):
466 filename = dialog.get_filename();
468 case(Gtk::RESPONSE_CANCEL):
487 if (m_ref_gconf_client) {
488 #ifdef GLIBMM_EXCEPTIONS_ENABLED 491 std::auto_ptr<Glib::Error> error;
494 g_warning(
"GConf error: %s", error->what().c_str());
495 #endif //GLIBMM_EXCEPTIONS_ENABLED 539 Glib::ustring msg = _(
"Saving changes...");
548 if (m_ref_gconf_client) {
549 #ifdef GLIBMM_EXCEPTIONS_ENABLED 553 std::auto_ptr<Glib::Error> error;
556 g_warning(
"GConf error: %s", error->what().c_str());
557 #endif //GLIBMM_EXCEPTIONS_ENABLED 598 if (m_ref_gconf_client) {
599 #ifdef GLIBMM_EXCEPTIONS_ENABLED 602 std::auto_ptr<Glib::Error> error;
605 g_warning(
"GConf error: %s", error->what().c_str());
606 #endif //GLIBMM_EXCEPTIONS_ENABLED 636 Glib::ustring status_msg;
637 if (op->is_finished())
638 status_msg = _(
"Print job completed");
640 status_msg = op->get_status_string();
649 if (result == Gtk::PRINT_OPERATION_RESULT_ERROR) {
650 Gtk::MessageDialog err_dialog(*this->
m_window, _(
"Error printing list"),
false,
651 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
true);
653 }
else if (result == Gtk::PRINT_OPERATION_RESULT_APPLY)
655 if (! op->is_finished())
666 op->set_items(items);
667 op->set_track_print_status();
673 #ifdef GLIBMM_EXCEPTIONS_ENABLED 676 }
catch (
const Gtk::PrintError& ex) {
677 g_error(
"An error occured while trying to run a print operation: %s", ex.what().c_str());
680 std::auto_ptr<Glib::Error> error;
681 op->run(Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG, error);
683 g_warning(
"Error running print job: %s",
684 error->what().c_str());
685 #endif //GLIBMM_EXCEPTIONS_ENABLED 697 Glib::ustring pdf_filename;
705 op->set_items(items);
706 op->set_track_print_status();
711 op->set_export_filename(pdf_filename);
713 #ifdef GLIBMM_EXCEPTIONS_ENABLED 715 op->run(Gtk::PRINT_OPERATION_ACTION_EXPORT);
716 }
catch (
const Gtk::PrintError& ex) {
717 g_error(
"An error occured while trying to run a print operation: %s", ex.what().c_str());
720 std::auto_ptr<Glib::Error> error;
721 op->run(Gtk::PRINT_OPERATION_ACTION_EXPORT, error);
723 g_warning(
"Error running print job: %s",
724 error->what().c_str());
725 #endif //GLIBMM_EXCEPTIONS_ENABLED 753 if (m_ref_gconf_client) {
754 #ifdef GLIBMM_EXCEPTIONS_ENABLED 757 std::auto_ptr<Glib::Error> error;
760 g_warning(
"GConf error: %s", error->what().c_str());
761 #endif //GLIBMM_EXCEPTIONS_ENABLED 779 Glib::RefPtr<Gtk::TreeSelection> ref_tree_selection =
781 if (ref_tree_selection) {
782 if (ref_tree_selection->get_mode() == Gtk::SELECTION_MULTIPLE) {
783 Gtk::TreeSelection::ListHandle_Path rows = ref_tree_selection->get_selected_rows();
784 for (Glib::Container_Helpers::ListHandleIterator<Gtk::TreePath_Traits> path = rows.begin(); path != rows.end(); ++path) {
786 Gtk::TreeModel::Row row = *iter;
790 retval->push_back(item);
792 g_warning(
"Failed to find item to delete in model");
796 Gtk::TreeModel::iterator iter = ref_tree_selection->get_selected();
798 Gtk::TreeModel::Row row = *iter;
802 retval->push_back(item);
804 g_warning(
"Failed to find item to delete in model");
807 g_warning(
"Couldn't find the selected item or items");
811 g_warning(
"Couldn't identify selection");
824 Glib::RefPtr<Gtk::TreeSelection> ref_tree_selection =
826 if (ref_tree_selection) {
827 if (ref_tree_selection->get_mode() == Gtk::SELECTION_MULTIPLE) {
831 Gtk::TreeModel::iterator iter = ref_tree_selection->get_selected();
833 Gtk::TreeModel::Row row = *iter;
837 g_warning(
"Failed to find the item to delete in the model");
839 g_warning(
"Couldn't find the selected item or items");
843 g_warning(
"Couldn't identify selection");
856 Gtk::MessageDialog dialog(*
m_window,
857 _(
"Delete the selected items?"),
859 Gtk::MESSAGE_QUESTION,
860 Gtk::BUTTONS_YES_NO);
861 int result = dialog.run();
863 case (Gtk::RESPONSE_YES) :
866 case (Gtk::RESPONSE_NO) :
869 g_warning(
"Unexpected button");
879 xmlpp::Document document;
880 xmlpp::Element* nodeRoot = document.create_root_node(
"kitlist");
882 nodeRoot->add_child_text(
"\n");
884 for (
ModelItemIter i = items->begin(); i != items->end(); ++i) {
885 xmlpp::Element* nodeChild = nodeRoot->add_child(
"item");
887 os << (*i)->get_id();
890 nodeChild->set_child_text((*i)->get_description());
891 nodeRoot->add_child_text(
"\n");
895 Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
896 std::list<Gtk::TargetEntry> listTargets;
899 refClipboard->set( listTargets,
948 Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
962 Glib::RefPtr<Gtk::TreeSelection> selection =
965 selection->select_all();
982 g_warning(
"\"window_add_category\" resource is missing");
1006 if (category != NULL) {
1041 Gtk::MessageDialog dialog(*
m_window,
1042 _(
"Delete the current category?"),
1044 Gtk::MESSAGE_QUESTION,
1045 Gtk::BUTTONS_YES_NO);
1046 int result = dialog.run();
1048 case (Gtk::RESPONSE_YES) :
1053 case (Gtk::RESPONSE_NO) :
1056 g_warning(
"Unexpected button");
1085 g_warning(
"\"window_add_category\" resource is missing");
1094 Gtk::AboutDialog dialog;
1095 dialog.set_name(PACKAGE_NAME);
1096 dialog.set_copyright(
"(c) 2008-2021 Frank Dean");
1097 dialog.set_version(PACKAGE_VERSION);
1098 std::vector<Glib::ustring> authors;
1099 authors.push_back(
"frank.dean@fdsd.co.uk");
1100 dialog.set_authors(authors);
1131 const std::string target = selection_data.get_target();
1138 g_warning(
"KitList::on_clipboard_get(): Unexpected clipboard target format");
1186 if (document.length() > 0) {
1187 xmlpp::DomParser parser;
1188 parser.set_substitute_entities();
1189 parser.parse_memory(document);
1190 const xmlpp::Node* nodeRoot = parser.get_document()->get_root_node();
1192 xmlpp::Node::NodeList nodes = nodeRoot->get_children();
1193 for (xmlpp::Node::NodeList::iterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
1194 const xmlpp::Node* node = (*iter);
1196 const xmlpp::Element* nodeElement =
dynamic_cast<const xmlpp::Element*
>(node);
1197 if (nodeElement && node->get_name() ==
"item") {
1198 xmlpp::Attribute* attribute = nodeElement->get_attribute(
XML_ELEMENT_ID);
1200 Glib::ustring s = attribute->get_value();
1201 long id = atol(s.c_str());
1204 items.push_back(item);
1211 }
catch (std::exception ex) {
1212 g_warning(
"Error pasting clipboard - perhaps it was empty");
1221 const std::string target = selection_data.get_target();
1226 g_warning(
"KitList::on_clipboard_get(): Unexpected clipboard target format");
1237 os.imbue(std::locale(
""));
1238 os << n <<
" " << (n == 1 ? _(
"item") : _(
"items"));
1241 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1244 std::auto_ptr<Glib::Error> ex;
1248 g_warning(
"Error updating the status bar: %s", ex->what().c_str());
1249 #endif // GLIBMM_EXCEPTIONS_ENABLED 1277 bool retval =
false;
1280 Gtk::FileChooserDialog dialog(_(
"Save File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1281 dialog.set_transient_for(*
m_window);
1283 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1284 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1286 Gtk::FileFilter filter_xml;
1287 filter_xml.set_name(_(
"XML files"));
1296 dialog.add_filter(filter_xml);
1298 Gtk::FileFilter filter_any;
1299 filter_any.set_name(_(
"Any files"));
1300 filter_any.add_pattern(
"*");
1301 dialog.add_filter(filter_any);
1303 int result = dialog.run();
1307 case(Gtk::RESPONSE_OK):
1308 filename = dialog.get_filename();
1311 case(Gtk::RESPONSE_CANCEL):
1318 Glib::ustring::size_type i = filename.find(
".");
1319 if (i < 0 || i > filename.length()) {
1325 Gtk::MessageDialog dialog(*
m_window,
1326 _(
"Overwrite existing file?"),
1328 Gtk::MESSAGE_WARNING,
1330 dialog.add_button(Gtk::Stock::NO, Gtk::RESPONSE_NO);
1331 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1332 dialog.add_button(Gtk::Stock::YES, Gtk::RESPONSE_YES);
1333 dialog.set_default_response(Gtk::RESPONSE_NO);
1334 int result = dialog.run();
1336 case (Gtk::RESPONSE_CANCEL) :
1340 case (Gtk::RESPONSE_NO) :
1344 case (Gtk::RESPONSE_YES) :
1375 bool retval =
false;
1378 Gtk::FileChooserDialog dialog(_(
"Export to PDF"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1379 dialog.set_transient_for(*
m_window);
1381 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1382 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1384 Gtk::FileFilter filter_pdf;
1385 filter_pdf.set_name(_(
"PDF files"));
1387 dialog.add_filter(filter_pdf);
1389 Gtk::FileFilter filter_any;
1390 filter_any.set_name(_(
"Any files"));
1391 filter_any.add_pattern(
"*");
1392 dialog.add_filter(filter_any);
1394 int result = dialog.run();
1398 case(Gtk::RESPONSE_OK):
1399 filename = dialog.get_filename();
1402 case(Gtk::RESPONSE_CANCEL):
1409 Glib::ustring::size_type i = filename.find(
".");
1410 if (i < 0 || i > filename.length()) {
1416 Gtk::MessageDialog dialog(*
m_window,
1417 _(
"Overwrite existing file?"),
1419 Gtk::MESSAGE_WARNING,
1421 dialog.add_button(Gtk::Stock::NO, Gtk::RESPONSE_NO);
1422 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1423 dialog.add_button(Gtk::Stock::YES, Gtk::RESPONSE_YES);
1424 dialog.set_default_response(Gtk::RESPONSE_NO);
1425 int result = dialog.run();
1427 case (Gtk::RESPONSE_CANCEL) :
1431 case (Gtk::RESPONSE_NO) :
1435 case (Gtk::RESPONSE_YES) :
1459 Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
1471 std::list<std::string> targets = targets_array;
1472 bool can_paste =
false;
1473 for (std::list<std::string>::iterator i = targets.begin(); i != targets.end(); ++i) {
1501 Gtk::TreeModel::Row row = *iter;
1506 g_warning(
"Unable to find the item in the model: %d",
id);
1514 Gtk::TreeModel::Row row = *iter;
1517 g_warning(
"Failed to find item to delete in model");
1554 if (items && !items->empty()) {
1555 for (
ItemIter i = items->begin(); i != items->end(); ++i) {
1560 Gtk::TreeModel::Row row = *item_iter;
1591 Gtk::TreeModel::iterator active;
1592 Gtk::TreeModel::Row row = *iter;
1595 os.imbue(std::locale(
""));
1596 os <<
"-- " << _(
"Show all items") <<
" --";
1597 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1600 std::auto_ptr<Glib::Error> ex;
1603 g_warning(
"Failed to add item to category combo model: %s", ex->what().c_str());
1608 for (
CategoryIter i = c->begin(); i != c->end(); ++i) {
1616 if (category->
get_id() == cat_id)
1622 if (!active || cat_id == -1)
1640 g_warning(
"\"entry_page_title\" resource is missing");
1643 g_warning(
"\"window_preferences\" resource is missing");
1650 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1653 std::auto_ptr<Glib::Error> error;
1656 g_warning(
"GConf error setting page title: %s",
1657 error->what().c_str());
1658 #endif //GLIBMM_EXCEPTIONS_ENABLED 1688 g_warning(
"\"window_add_item\" resource is missing");
1713 Gtk::TreeModel::Row row = *iter;
1774 Glib::ustring filename;
1777 #ifdef KITLIST_DEBUG 1778 Glib::ustring log_filename;
1779 #endif //KITLIST_DEBUB 1782 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1784 #endif //GLIBMM_EXCEPTIONS_ENABLED 1785 Gnome::Conf::init();
1786 m_ref_gconf_client = Gnome::Conf::Client::get_default_client();
1789 Gnome::Conf::Value value = Gnome::Conf::VALUE_INVALID;
1790 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1794 std::auto_ptr<Glib::Error> error;
1796 Gnome::Conf::CLIENT_PRELOAD_NONE,
1799 g_warning(
"GConf error: %s", error->what().c_str());
1802 g_warning(
"GConf error getting current filename: %s",
1803 error->what().c_str());
1804 #endif //GLIBMM_EXCEPTIONS_ENABLED 1805 if (value.get_type() == Gnome::Conf::VALUE_STRING) {
1806 filename = value.to_string();
1810 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1815 g_warning(
"GConf error getting page title: %s",
1816 error->what().c_str());
1817 #endif // GLIBMM_EXCEPTIONS_ENABLED 1818 if (value.get_type() == Gnome::Conf::VALUE_STRING) {
1820 }
else if (value.get_type() == Gnome::Conf::VALUE_INVALID) {
1826 #ifdef KITLIST_DEBUG 1827 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1828 value = m_ref_gconf_client->get(GCONF_KEY_DEBUG_LOG);
1830 value = m_ref_gconf_client->get(GCONF_KEY_DEBUG_LOG, error);
1832 g_warning(
"GConf error getting log filename: %s",
1833 error->what().c_str());
1834 #endif // GLIBMM_EXCEPTIONS_ENABLED 1835 if (value.get_type() == Gnome::Conf::VALUE_STRING) {
1836 log_filename = value.to_string();
1837 }
else if (value.get_type() == Gnome::Conf::VALUE_INVALID) {
1838 log_filename =
"/tmp/kitlist.log";
1839 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1840 m_ref_gconf_client->set(GCONF_KEY_DEBUG_LOG, log_filename);
1842 std::auto_ptr<Glib::Error> error;
1843 m_ref_gconf_client->set(GCONF_KEY_DEBUG_LOG, log_filename, error);
1845 g_warning(
"GConf error setting log filename: %s",
1846 error->what().c_str());
1847 #endif //GLIBMM_EXCEPTIONS_ENABLED 1849 #endif //KITLIST_DEBUG 1851 #ifdef GLIBMM_EXCEPTIONS_ENABLED 1852 }
catch (
const Glib::Error& ex) {
1853 g_warning(
"GConf error: %s", ex.what().c_str());
1855 #endif //GLIBMM_EXCEPTIONS_ENABLED 1860 #ifdef KITLIST_DEBUG 1862 #endif //KITLIST_DEBUG 1865 #ifdef KITLIST_DEBUG 1866 m_slog =
new ofstream(log_filename.c_str(), ios_base::trunc);
1867 g_log_set_handler(NULL, (GLogLevelFlags) (G_LOG_LEVEL_MASK |
1868 G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
1869 my_log_handler, m_slog);
1870 #endif //KITLIST_DEBUG 1873 refXml->get_widget(
"main",
m_window);
1882 Gtk::MenuItem* p_menu_item = 0;
1883 refXml->get_widget(
"menu_file_quit", p_menu_item);
1886 Gtk::ToolButton* p_tool_button = 0;
1887 refXml->get_widget(
"tool_button_quit", p_tool_button);
1893 refXml->get_widget(
"menu_preferences", p_menu_item);
1899 refXml->get_widget(
"menu_delete_item", p_menu_item);
1903 refXml->get_widget(
"tool_button_delete", p_tool_button);
1909 refXml->get_widget(
"menu_add_item", p_menu_item);
1913 refXml->get_widget(
"tool_button_add", p_tool_button);
1917 Gtk::Button* p_button = 0;
1918 refXml->get_widget(
"preferences_ok_button", p_button);
1921 refXml->get_widget(
"preferences_cancel_button", p_button);
1924 refXml->get_widget(
"add_item_ok_button", p_button);
1928 refXml->get_widget(
"add_item_cancel_button", p_button);
1938 refXml->get_widget(
"menu_new", p_menu_item);
1944 refXml->get_widget(
"tool_button_new", p_tool_button);
1945 if (p_tool_button) {
1952 refXml->get_widget(
"menu_open", p_menu_item);
1958 refXml->get_widget(
"tool_button_open", p_tool_button);
1959 if (p_tool_button) {
1975 refXml->get_widget(
"menu_save_as", p_menu_item);
1978 #ifdef TRANSITION_DAO 1979 p_menu_item->set_sensitive(
true);
1987 refXml->get_widget(
"menu_print", p_menu_item);
1991 refXml->get_widget(
"tool_button_print", p_tool_button);
1996 refXml->get_widget(
"menu_export_pdf", p_menu_item);
2005 refXml->get_widget(
"menu_cut", p_menu_item);
2009 refXml->get_widget(
"tool_button_cut", p_tool_button);
2015 refXml->get_widget(
"menu_copy", p_menu_item);
2019 refXml->get_widget(
"tool_button_copy", p_tool_button);
2033 refXml->get_widget(
"show_all", p_menu_item);
2037 refXml->get_widget(
"tool_button_show_all", p_tool_button);
2043 refXml->get_widget(
"show_checked", p_menu_item);
2047 refXml->get_widget(
"tool_button_show_checked", p_tool_button);
2053 refXml->get_widget(
"show_unchecked", p_menu_item);
2057 refXml->get_widget(
"tool_button_show_unchecked", p_tool_button);
2063 refXml->get_widget(
"refresh_view", p_menu_item);
2067 refXml->get_widget(
"tool_button_refresh", p_tool_button);
2073 refXml->get_widget(
"select_all", p_menu_item);
2077 refXml->get_widget(
"tool_button_select_all", p_tool_button);
2083 refXml->get_widget(
"check_selected", p_menu_item);
2087 refXml->get_widget(
"tool_button_check_selected", p_tool_button);
2093 refXml->get_widget(
"uncheck_selected", p_menu_item);
2097 refXml->get_widget(
"tool_button_uncheck_selected", p_tool_button);
2103 refXml->get_widget(
"toggle_selected", p_menu_item);
2107 refXml->get_widget(
"tool_button_toggle_selected", p_tool_button);
2113 refXml->get_widget(
"create_category", p_menu_item);
2124 refXml->get_widget(
"add_category_ok_button", p_button);
2128 refXml->get_widget(
"add_category_cancel_button", p_button);
2136 refXml->get_widget(
"delete_category", p_menu_item);
2142 refXml->get_widget(
"rename_category", p_menu_item);
2148 refXml->get_widget(
"help_about", p_menu_item);
2167 if (!items->empty()) {
2169 for (
ItemIter i = items->begin(); i != items->end(); ++i) {
2172 Gtk::TreeModel::Row row = *itemIter;
2193 Glib::RefPtr<Gtk::TreeSelection> ref_tree_selection =
2195 ref_tree_selection->set_mode(Gtk::SELECTION_MULTIPLE);
2199 if (filename.length() == 0 || !
file_exists(filename)) {
2201 filename = Glib::build_filename(
2202 Glib::get_home_dir(),
2207 if (filename.length() > 0 &&
file_exists(filename)) {
void run()
Starts the GUI application running.
virtual bool choose_pdf_filename(Glib::ustring &filename)
Displays a file chooser dialog for a user to choose a filename for export to PDF. ...
virtual void cancel_add_category_window()
Called when the add/rename category dialog is closed using the 'Cancel' button.
Gtk::MenuItem * m_recent_files_menu_item
The recent files menu item.
Gtk::ComboBox * m_category_combo
The combo box holding a list of categories.
Gtk::Window * m_window_preferences
The 'Preferences' dialog.
Gtk::TreeModel::Children type_children
ModelItemContainer::iterator ModelItemIter
virtual void on_menu_show_all()
Causes all items to be displayed.
virtual void on_menu_delete()
Called when the user chooses to delete items.
virtual void on_menu_cut()
virtual bool on_delete_event(GdkEventAny *event)
Called when the application is closed by the user.
Gtk::Window * m_window
The main application window.
ModelCategory * find_category(long cat_id)
const Glib::ustring GCONF_KEY_CURRENT_FILENAME
GConf entry for the current filename.
const Glib::ustring GCONF_KEY_MAX_RECENT_FILES
GConf entry for max recent files.
Glib::ustring get_debug_log_filename()
the name of the debug log file.
void on_printoperation_status_changed(const Glib::RefPtr< Gtk::PrintOperation > &op)
Called when the print status changes.
virtual void on_menu_create_category()
Called when the user chooses to create a new category.
Category * create_category()
Creates a new category.
enum gui_state m_state
Indicates whether a category is being created or renamed.
Gtk::Window * m_window_add_category
The 'Add Category' dialog.
Represents a Category combined with GuiState attributes.
virtual void on_menu_quit()
Called when the user chooses to quit the application.
virtual void update_item_count(size_t n)
const guint SB_SAVE
Status bar message constant for save notifications.
virtual void select_items(ModelItemContainer *items, bool checked=true)
Checks or unchecks all the passed items.
virtual void update_recent_files_menu()
Updates the recent files sub menu.
ItemContainer::iterator ItemIter
CategoryContainer::iterator CategoryIter
virtual void delete_selected_items()
Deletes the currently selected items.
long m_current_cat_id
temporary reference to a category id, usually being renamed
Gtk::Entry * m_entry_page_title
the text entry field for the page title
virtual void update_recent_files(const Glib::ustring &filename)
virtual void on_menu_recent_file(const Glib::ustring &filename)
displays the most recent files menu
Glib::ustring m_page_title
The page title to be used when printing the item list.
void set_dirty(bool dirty=true)
virtual void close_add_category_window()
Called when the add/rename category dialog is closed using the 'OK' button.
const bool file_exists(const Glib::ustring &filename)
Returns true if the passed file exists.
Gtk::Window * m_window_add_item
The 'Add Item' dialog.
virtual void init_add_item_window()
std::vector< Item * > ItemContainer
Gtk::CheckButton * m_checkbutton_add_item
The check button field of the 'Add Item' dialog.
Gtk::TreeModelColumn< int > m_col_num
Gtk::Statusbar * m_status_bar
The application status bar.
virtual void set_selected(bool checked)
ModelItemColumns m_item_cols
The definition of the item list's columns.
void add_recent_filename(Glib::ustring filename)
Adds a filename to the list of recently used filenames.
virtual void remove_items(ModelItemContainer *items)
Removes all the passed items from this ModelCategory.
virtual void set_checked(bool checked)
virtual void on_menu_save()
Saves the current application state.
Gtk::ToolButton * m_paste_tool_button
The toolbar paste button.
void set_name(const std::string name)
virtual void cancel_add_item_window()
Glib::ustring get_current_filename()
The current filename.
Gtk::Entry * m_entry_add_category
The text entry field of the 'Add Category' dialog.
void set_current_filename(Glib::ustring filename)
Sets the current filename.
virtual void on_clipboard_clear()
This method gets called after a second 'copy' operation.
virtual void on_menu_check_selected()
Marks all selected items as checked.
Gtk::Entry * m_entry_add_item
The text entry field of the 'Add Item' dialog.
const string GLADE_APP_FILE
Resource file name.
virtual void on_menu_show_unchecked()
Causes only unchecked items to be displayed.
virtual void on_category_change()
void open_as_xml(const Glib::ustring &filename)
Loads a new data model from the named XML document.
KitListGui(int argc, char **argv, Service &service)
virtual void set_page_title(const Glib::ustring page_title)
virtual void open_file(const Glib::ustring &filename)
Opens an existing XML document.
Service & m_service
The business/service object.
Glib::RefPtr< Gtk::PageSetup > m_ref_page_setup
Printer page setup settings.
Comparator used for sorting Items by name.
ItemContainer * get_items(long cat_id=-1)
Returns a list of items.
std::vector< ModelItem * > ModelItemContainer
Item * create_item(long cat_id)
Creates a new ModelItem and associates it with the specified category.
virtual long get_selected_category()
Returns the ID of the currently selected Category.
Gtk::Main m_kit
The main application.
Glib::RefPtr< Gtk::ListStore > m_ref_item_tree_model
The model backing the item list.
bool m_ignore_list_events
Temporarily ignore events on the item list.
Gtk::TreeModelColumn< Glib::ustring > m_col_text
virtual void on_menu_paste()
Called when the user chooses the 'paste' menu option.
Glib::RefPtr< Gnome::Glade::Xml > get_glade_ref_ptr(const string &filename, const Glib::ustring &root=Glib::ustring(), const Glib::ustring &domain=Glib::ustring())
Returns a reference to the Glade resource file.
virtual void on_clipboard_received(const Gtk::SelectionData &selection_data)
bool delete_category(long cat_id)
Flags a category as deleted.
Glib::ustring m_filename
The filename currently associated with the loaded model.
const std::string DEFAULT_PAGE_TITLE
The default page title for printing.
virtual ModelItemContainer * get_selected_items()
Returns a list of items selected in the item list.
Glib::ustring get_page_title()
The page title to use for printing or creating a PDF.
const char item_target_custom[]
Key used for custom clipboard.
const char XML_ELEMENT_ID[]
Tag name for the ID element in the clipbard XML document.
virtual void on_menu_show_checked()
Causes only checked items to be displayed.
virtual void on_menu_preferences()
void on_printoperation_done(Gtk::PrintOperationResult result, const Glib::RefPtr< Gtk::PrintOperation > &op)
Called when the printer operation is done.
Glib::ustring m_clipboard_items
Holder for items pasted to the clipboard.
virtual void cancel_preferences_window()
virtual void paste_status_received(const Glib::StringArrayHandle &targets_array)
virtual bool choose_filename(Glib::ustring &filename)
Displays a file chooser dialog for a user to choose a filename.
virtual void add_items(const ModelItemContainer &items)
Associates the passed list of items with the currently selected category.
void save_as_xml(const Glib::ustring &filename)
Saves the model's state to an XML document.
virtual void close_preferences_window()
CategoryContainer * get_categories()
Returns a list of all categories.
bool update_item(long id, const std::string description, bool checked)
Updates the attributes of an item.
virtual ModelItemContainer * copy_selected_items_to_clipboard()
Gtk::ImageMenuItem * m_paste_menu_item
The menu paste button.
virtual void on_menu_file_open()
Allows the user to open an existing XML document.
virtual void on_clipboard_get(Gtk::SelectionData &selection_date, guint)
virtual void on_menu_help_about()
const guint SB_ITEM_COUNT
Status bar message constant for displaying item counts.
const string load_resource_glade_file(const Glib::ustring &filename)
Locate the Glade resource file from a list of potential locations.
void set_page_title(Glib::ustring title)
Set the page title.
Gtk::TreeModelColumn< int > m_col_num
virtual void update_paste_status()
Enables or disables the paste menu option.
virtual void on_menu_add()
Represents an Item combined with GuiState attributes.
static Glib::RefPtr< KitPrintOperation > create()
Factory to create instances.
virtual void toggle_selected_items(ModelItemContainer *items)
Toggles the checked state of all the passed items.
void copy_items(const ModelItemContainer &items, long cat_id)
Copies items to the specified category.
bool delete_item(long id)
Flags an item as deleted.
virtual void close_add_item_window()
Glib::RefPtr< Gtk::ListStore > m_ref_category_list_store
The model backing the category combo box.
virtual void on_menu_rename_category()
Called when the user chooses to rename a category.
virtual void on_menu_delete_category()
Called when the user chooses the delete category menu option.
Gtk::ImageMenuItem * m_file_save_menu_item
The file save menu item.
virtual bool confirm_lose_changes(const Glib::ustring &message)
Shows a confirmation message.
const Glib::ustring DEFAULT_FILENAME
The default filename.
virtual gint get_max_recent_files()
virtual void toggle_selected()
Comparator used for sorting Categories by name.
const gint DEFAULT_MAX_RECENT_FILES
The maximum number of recent files to maintain.
const char item_target_text[]
Mime type for clipboard content.
virtual void on_menu_select_all()
Called when the user chooses the 'select all' menu option.
const Glib::ustring PDF_FILENAME_EXTENSION
PDF filename extension.
ItemContainer * get_filtered_items(long cat_id=-1)
Returns a list of items, applying the current filter.
Gtk::TreeView * m_item_tree_view
The item list view definition.
virtual void refresh_category_list(long cat_id=-2)
Refreshes the category combo box list.
const guint SB_PRINT
Status bar message constant for printer messages.
virtual void on_menu_print()
Prints the kit list.
std::vector< Category * > CategoryContainer
virtual bool require_filename()
const guint SB_MSG
Status bar message constant for general messages.
const Glib::ustring GCONF_KEY_RECENT_FILES
GConf entry for recent files.
virtual void safe_open_file(const Glib::ustring &filename)
Opens an existing XML document, checking for unsaved changes.
virtual void on_menu_uncheck_selected()
Marks all selected items as unchecked.
Gtk::TreeModelColumn< Glib::ustring > m_col_text
Glib::RefPtr< Gtk::PrintSettings > m_ref_printer_settings
Printer settings.
void set_model_dirty(bool flag=true)
virtual void selected_row_callback(const Gtk::TreeModel::iterator &iter)
void on_row_changed(const Gtk::TreeModel::Path path, const Gtk::TreeModel::iterator iter)
Callback method called when an item has been modified in the item list.
virtual void on_cell_edit(const Glib::ustring s)
Callback method called when a cell has been edited in the item list.
const Glib::ustring DEFAULT_FILENAME_EXTENSION
Default filename extension.
Gtk::TreeModelColumn< bool > m_col_checked
void create_default_model()
Creates a default model.
virtual void on_menu_save_as()
Saves the current application state in a new document.
const Glib::ustring GCONF_KEY
The application's root key in the GConf hierarchy.
virtual void on_menu_export_to_pdf()
std::deque< Glib::ustring > get_recent_filenames()
The history list of recent filenames.
ModelItem * find_item(long id)
void set_description(const std::string description)
virtual void paste_from_xml(const Glib::ustring &document)
virtual void raise()
Make this application topmost.
virtual bool filter(bool checked)
Applies the current filter.
Gtk::ToolButton * m_file_save_tool_button
The file save toolbar button.
Business/service layer implementation.
ModelCategoryColumns m_category_cols
The definition of the category combo box columns.
virtual void refresh_item_list()
virtual void on_menu_copy()
Called when the use chooses the 'copy' menu option.
virtual void on_menu_file_new()
Creates a new empty model.
const Glib::ustring GCONF_KEY_PAGE_TITLE
GConf entry for the page title.