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 00051 enum gui_state { ADD_CATEGORY, RENAME_CATEGORY }; 00052 00056 class ModelCategoryColumns : public Gtk::TreeModel::ColumnRecord { 00057 public: 00058 00059 ModelCategoryColumns() { 00060 add(m_col_text); 00061 add(m_col_num); 00062 } 00063 00064 Gtk::TreeModelColumn<Glib::ustring> m_col_text; 00065 Gtk::TreeModelColumn<int> m_col_num; 00066 }; 00067 00068 00070 const int CHECKED_COL_POSITION = 0; 00071 00075 class ModelItemColumns : public Gtk::TreeModel::ColumnRecord { 00076 public: 00077 00078 ModelItemColumns() { 00079 add(m_col_text); 00080 add(m_col_checked); 00081 add(m_col_num); 00082 } 00083 00084 Gtk::TreeModelColumn<Glib::ustring> m_col_text; 00085 Gtk::TreeModelColumn<bool> m_col_checked; 00086 Gtk::TreeModelColumn<int> m_col_num; 00087 00088 }; 00089 00090 00097 class KitListGui { 00098 protected: 00099 #ifdef GCONF 00101 Glib::RefPtr<Gnome::Conf::Client> m_ref_gconf_client; 00102 #endif 00103 00108 Glib::ustring m_filename; 00109 #ifdef KITLIST_DEBUG 00111 std::ofstream* m_slog; 00112 #endif 00114 Glib::ustring m_clipboard_items; 00116 bool m_ignore_list_events; 00118 Gtk::Main m_kit; 00119 #ifdef MAEMO 00121 Hildon::Window* m_window; 00123 Glib::RefPtr<Gtk::UIManager> m_refUIManager; 00125 Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup; 00126 // The 'Add Item' dialog 00127 // Hildon::Window* m_window_add_item; 00128 #else 00130 Gtk::Window* m_window; 00131 #endif 00133 Gtk::Window* m_window_add_item; 00135 Gtk::Window* m_window_add_category; 00137 Gtk::Entry* m_entry_add_item; 00139 Gtk::Entry* m_entry_add_category; 00141 Gtk::ImageMenuItem* m_file_save_menu_item; 00143 Gtk::ToolButton* m_file_save_tool_button; 00145 Gtk::MenuItem* m_recent_files_menu_item; 00147 Gtk::ImageMenuItem* m_paste_menu_item; 00148 #ifdef MAEMO 00150 Gtk::ToolButton* m_paste_tool_button; 00151 #endif 00153 Gtk::CheckButton* m_checkbutton_add_item; 00155 Gtk::ComboBox* m_category_combo; 00157 Glib::RefPtr<Gtk::ListStore> m_ref_category_list_store; 00159 ModelCategoryColumns m_category_cols; 00161 Gtk::TreeView* m_item_tree_view; 00163 ModelItemColumns m_item_cols; 00165 Service& m_service; 00167 Glib::RefPtr<Gtk::ListStore> m_ref_item_tree_model; 00169 Gtk::Statusbar* m_status_bar; 00170 00177 enum gui_state m_state; 00178 long m_current_cat_id; 00179 virtual void init(); 00180 virtual gint get_max_recent_files(); 00181 #ifdef MAEMO 00183 bool m_full_screen; 00184 virtual bool on_window_state_event(GdkEventWindowState* event); 00185 virtual bool on_key_pressed(GdkEventKey* key); 00186 virtual void show_banner(const Glib::ustring& msg); 00187 #endif 00188 virtual ModelItemContainer* get_selected_items(); 00189 virtual void add_items(const ModelItemContainer& items); 00190 virtual void close_add_item_window(); 00191 virtual void cancel_add_item_window(); 00192 virtual void close_add_category_window(); 00193 virtual void cancel_add_category_window(); 00194 virtual long get_selected_category(); 00195 virtual void init_add_item_window(); 00196 virtual void delete_selected_items(); 00197 virtual ModelItemContainer* copy_selected_items_to_clipboard(); 00198 virtual bool confirm_lose_changes(const Glib::ustring& message); 00199 virtual void update_recent_files_menu(); 00200 virtual void update_recent_files(const Glib::ustring& filename); 00201 virtual bool on_delete_event(GdkEventAny* event); 00202 virtual void on_menu_quit(); 00203 virtual void on_menu_file_new(); 00204 virtual void on_menu_file_open(); 00205 virtual void on_menu_save(); 00206 virtual void on_menu_save_as(); 00207 virtual void on_menu_recent_file(const Glib::ustring& filename); 00208 virtual void on_menu_add(); 00209 virtual void on_menu_delete(); 00210 virtual void on_menu_cut(); 00211 virtual void on_menu_copy(); 00212 virtual void on_menu_paste(); 00214 virtual void on_menu_show_all() { m_service.show_all(); refresh_item_list(); } 00216 virtual void on_menu_show_checked() { m_service.show_checked_only(); refresh_item_list(); } 00218 virtual void on_menu_show_unchecked() { m_service.show_unchecked_only(); refresh_item_list(); } 00219 virtual void on_menu_select_all(); 00221 virtual void on_menu_check_selected() { set_selected(true); } 00223 virtual void on_menu_uncheck_selected() { set_selected(false); } 00224 virtual void on_menu_create_category(); 00225 virtual void on_menu_delete_category(); 00226 virtual void on_menu_rename_category(); 00227 virtual void on_menu_help_about(); 00228 virtual void on_menu_help_contents(); 00229 virtual void on_clipboard_get(Gtk::SelectionData& selection_date, guint); 00230 virtual void on_clipboard_clear(); 00231 virtual void on_clipboard_received(const Gtk::SelectionData& selection_data); 00232 virtual void on_category_change(); 00233 virtual void on_cell_edit(const Glib::ustring s); 00234 virtual bool choose_filename(Glib::ustring& filename); 00235 virtual void update_paste_status(); 00236 virtual void paste_status_received(const Glib::StringArrayHandle& targets_array); 00237 virtual void paste_from_xml(const Glib::ustring& document); 00238 virtual void refresh_item_list(); 00239 virtual void refresh_category_list(long cat_id = -2); 00240 virtual void selected_row_callback(const Gtk::TreeModel::iterator& iter); 00241 virtual void set_selected(bool checked); 00242 virtual void toggle_selected(); 00243 // virtual void on_row_deleted(Gtk::TreeModel::Path path); 00244 void on_row_changed(const Gtk::TreeModel::Path path, const Gtk::TreeModel::iterator iter); 00245 virtual void update_item_count(size_t n); 00246 public: 00247 KitListGui(int argc, char **argv, Service& service); 00248 ~KitListGui(); 00249 virtual void open_file(const Glib::ustring& filename); 00250 #ifdef MAEMO 00251 osso_context_t* m_osso_context; 00252 #endif 00253 virtual void raise(); 00254 virtual void safe_open_file(const Glib::ustring& filename); 00255 void run(); 00256 }; 00257 00258 00259 #endif // KIT_LIST_GUI_H