00001 /* 00002 00003 This file is part of Kitlist, a program to maintain a simple list 00004 of items and assign items to one or more categories. 00005 00006 Copyright (C) 2008,2009 Frank Dean 00007 00008 Kitlist is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 Kitlist is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Kitlist. If not, see <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #ifndef KIT_LIST_GUI_H 00024 #define KIT_LIST_GUI_H 1 00025 00026 #include "service.hpp" 00027 00028 #ifdef MAEMO 00029 #include <hildonmm.h> 00030 #include <hildon-fmmm.h> 00031 #endif 00032 #include <iostream> 00033 #ifdef KITLIST_DEBUG 00034 #include <fstream> 00035 #endif 00036 #ifdef GCONF 00037 #include <gconfmm/client.h> 00038 #include <gconfmm.h> 00039 #endif 00040 #include <gtkmm/button.h> 00041 #include <gtkmm/checkbutton.h> 00042 #include <gtkmm/combobox.h> 00043 #include <gtkmm/entry.h> 00044 #include <gtkmm/imagemenuitem.h> 00045 #include <gtkmm/main.h> 00046 #include <gtkmm/statusbar.h> 00047 #include <gtkmm/toolbutton.h> 00048 #include <gtkmm/treemodelcolumn.h> 00049 #include <gtkmm/liststore.h> 00050 #include <gtkmm/pagesetup.h> 00051 #include <gtkmm/printsettings.h> 00052 #include <gtkmm/printoperation.h> 00053 00054 enum gui_state { ADD_CATEGORY, RENAME_CATEGORY }; 00055 00059 class ModelCategoryColumns : public Gtk::TreeModel::ColumnRecord { 00060 public: 00061 00062 ModelCategoryColumns() { 00063 add(m_col_text); 00064 add(m_col_num); 00065 } 00066 00067 Gtk::TreeModelColumn<Glib::ustring> m_col_text; 00068 Gtk::TreeModelColumn<int> m_col_num; 00069 }; 00070 00071 00073 const int CHECKED_COL_POSITION = 0; 00074 00078 class ModelItemColumns : public Gtk::TreeModel::ColumnRecord { 00079 public: 00080 00081 ModelItemColumns() { 00082 add(m_col_text); 00083 add(m_col_checked); 00084 add(m_col_num); 00085 } 00086 00087 Gtk::TreeModelColumn<Glib::ustring> m_col_text; 00088 Gtk::TreeModelColumn<bool> m_col_checked; 00089 Gtk::TreeModelColumn<int> m_col_num; 00090 00091 }; 00092 00093 00100 class KitListGui { 00101 protected: 00102 #ifdef GCONF 00104 Glib::RefPtr<Gnome::Conf::Client> m_ref_gconf_client; 00105 #endif 00106 00111 Glib::ustring m_filename; 00113 Glib::ustring m_page_title; 00114 #ifdef KITLIST_DEBUG 00116 std::ofstream* m_slog; 00117 #endif 00119 Glib::ustring m_clipboard_items; 00121 bool m_ignore_list_events; 00123 Gtk::Main m_kit; 00124 #ifdef MAEMO 00126 Hildon::Window* m_window; 00128 Glib::RefPtr<Gtk::UIManager> m_refUIManager; 00130 Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup; 00131 // The 'Add Item' dialog 00132 // Hildon::Window* m_window_add_item; 00133 #else 00135 Gtk::Window* m_window; 00136 #endif 00138 Gtk::Window* m_window_preferences; 00140 Gtk::Entry* m_entry_page_title; 00142 Gtk::Window* m_window_add_item; 00144 Gtk::Window* m_window_add_category; 00146 Gtk::Entry* m_entry_add_item; 00148 Gtk::Entry* m_entry_add_category; 00150 Gtk::ImageMenuItem* m_file_save_menu_item; 00152 Gtk::ToolButton* m_file_save_tool_button; 00154 Gtk::MenuItem* m_recent_files_menu_item; 00156 Gtk::ImageMenuItem* m_paste_menu_item; 00158 Gtk::ToolButton* m_paste_tool_button; 00160 Gtk::CheckButton* m_checkbutton_add_item; 00162 Gtk::ComboBox* m_category_combo; 00164 Glib::RefPtr<Gtk::ListStore> m_ref_category_list_store; 00166 ModelCategoryColumns m_category_cols; 00168 Gtk::TreeView* m_item_tree_view; 00170 ModelItemColumns m_item_cols; 00172 Service& m_service; 00174 Glib::RefPtr<Gtk::ListStore> m_ref_item_tree_model; 00176 Gtk::Statusbar* m_status_bar; 00178 Glib::RefPtr<Gtk::PageSetup> m_ref_page_setup; 00180 Glib::RefPtr<Gtk::PrintSettings> m_ref_printer_settings; 00181 00188 enum gui_state m_state; 00189 long m_current_cat_id; 00190 virtual void init(); 00191 virtual gint get_max_recent_files(); 00192 #ifdef MAEMO 00194 bool m_full_screen; 00195 virtual bool on_window_state_event(GdkEventWindowState* event); 00196 virtual bool on_key_pressed(GdkEventKey* key); 00197 virtual void show_banner(const Glib::ustring& msg); 00198 #endif 00199 virtual ModelItemContainer* get_selected_items(); 00200 virtual void add_items(const ModelItemContainer& items); 00201 virtual void set_page_title(const Glib::ustring page_title); 00202 virtual void close_preferences_window(); 00203 virtual void cancel_preferences_window(); 00204 virtual void close_add_item_window(); 00205 virtual void cancel_add_item_window(); 00206 virtual void close_add_category_window(); 00207 virtual void cancel_add_category_window(); 00208 virtual long get_selected_category(); 00209 virtual void init_add_item_window(); 00210 virtual void delete_selected_items(); 00211 virtual ModelItemContainer* copy_selected_items_to_clipboard(); 00212 virtual bool confirm_lose_changes(const Glib::ustring& message); 00213 virtual void update_recent_files_menu(); 00214 virtual void update_recent_files(const Glib::ustring& filename); 00215 virtual bool on_delete_event(GdkEventAny* event); 00216 virtual void on_menu_quit(); 00217 virtual void on_menu_file_new(); 00218 virtual void on_menu_file_open(); 00219 virtual void on_menu_save(); 00220 virtual void on_menu_save_as(); 00221 void on_printoperation_done(Gtk::PrintOperationResult result, const Glib::RefPtr<Gtk::PrintOperation>& op); 00222 void on_printoperation_status_changed(const Glib::RefPtr<Gtk::PrintOperation>& op); 00223 virtual void on_menu_print(); 00224 virtual void on_menu_export_to_pdf(); 00225 virtual void on_menu_recent_file(const Glib::ustring& filename); 00226 virtual void on_menu_preferences(); 00227 virtual void on_menu_add(); 00228 virtual void on_menu_delete(); 00229 virtual void on_menu_cut(); 00230 virtual void on_menu_copy(); 00231 virtual void on_menu_paste(); 00233 virtual void on_menu_show_all() { m_service.show_all(); refresh_item_list(); } 00235 virtual void on_menu_show_checked() { m_service.show_checked_only(); refresh_item_list(); } 00237 virtual void on_menu_show_unchecked() { m_service.show_unchecked_only(); refresh_item_list(); } 00238 virtual void on_menu_select_all(); 00240 virtual void on_menu_check_selected() { set_selected(true); } 00242 virtual void on_menu_uncheck_selected() { set_selected(false); } 00243 virtual void on_menu_create_category(); 00244 virtual void on_menu_delete_category(); 00245 virtual void on_menu_rename_category(); 00246 virtual void on_menu_help_about(); 00247 virtual void on_menu_help_contents(); 00248 virtual void on_clipboard_get(Gtk::SelectionData& selection_date, guint); 00249 virtual void on_clipboard_clear(); 00250 virtual void on_clipboard_received(const Gtk::SelectionData& selection_data); 00251 virtual void on_category_change(); 00252 virtual void on_cell_edit(const Glib::ustring s); 00253 virtual bool choose_filename(Glib::ustring& filename); 00254 virtual bool choose_pdf_filename(Glib::ustring& filename); 00255 virtual void update_paste_status(); 00256 virtual void paste_status_received(const Glib::StringArrayHandle& targets_array); 00257 virtual void paste_from_xml(const Glib::ustring& document); 00258 virtual void refresh_item_list(); 00259 virtual void refresh_category_list(long cat_id = -2); 00260 virtual void selected_row_callback(const Gtk::TreeModel::iterator& iter); 00261 virtual void set_selected(bool checked); 00262 virtual void toggle_selected(); 00263 // virtual void on_row_deleted(Gtk::TreeModel::Path path); 00264 void on_row_changed(const Gtk::TreeModel::Path path, const Gtk::TreeModel::iterator iter); 00265 virtual void update_item_count(size_t n); 00266 public: 00267 KitListGui(int argc, char **argv, Service& service); 00268 ~KitListGui(); 00269 virtual void open_file(const Glib::ustring& filename); 00270 #ifdef MAEMO 00271 osso_context_t* m_osso_context; 00272 #endif 00273 virtual void raise(); 00274 virtual void safe_open_file(const Glib::ustring& filename); 00275 void run(); 00276 }; 00277 00278 00279 #endif // KIT_LIST_GUI_H