]> Dogcows Code - chaz/tint2/blob - src/tint2conf/thumbview.h
play with some tint2conf code
[chaz/tint2] / src / tint2conf / thumbview.h
1 /*
2
3 This file is from Nitrogen, an X11 background setter.
4 Copyright (C) 2006 Dave Foster & Javeed Shaikh
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 */
21
22 #include <queue>
23 #include <errno.h>
24 #include <gtkmm.h>
25
26 #ifdef USE_INOTIFY
27 //#include "Inotify.h"
28 #endif
29
30 struct TreePair {
31 Glib::ustring file;
32 Gtk::TreeModel::iterator iter;
33 Glib::RefPtr<Gdk::Pixbuf> thumb;
34 };
35
36 class Thumbview;
37
38 class DelayLoadingStore : public Gtk::ListStore
39 {
40 public:
41 static Glib::RefPtr<DelayLoadingStore> create(const Gtk::TreeModelColumnRecord& columns)
42 {
43 return Glib::RefPtr<DelayLoadingStore>(new DelayLoadingStore(columns));
44 }
45
46 protected:
47 DelayLoadingStore() : Gtk::ListStore() {}
48 DelayLoadingStore(const Gtk::TreeModelColumnRecord& columns) : Gtk::ListStore(columns) {}
49
50 protected:
51 virtual void get_value_vfunc (const iterator& iter, int column, Glib::ValueBase& value) const;
52
53 public:
54 void set_queue(GAsyncQueue *queue) { aqueue_loadthumbs = queue; }
55 void set_thumbview(Thumbview *view) { thumbview = view; }
56
57 protected:
58 GAsyncQueue *aqueue_loadthumbs;
59 Thumbview *thumbview;
60
61
62 };
63
64 /////////////////////////////////////////////////////////////////////////////
65
66 /**
67 * Column record for the Thumbview store.
68 */
69 class ThumbviewRecord : public Gtk::TreeModelColumnRecord
70 {
71 public:
72 ThumbviewRecord()
73 {
74 add(Thumbnail);
75 add(Description);
76 add(Filename);
77 add(Time);
78 add(LoadingThumb);
79 add(CurBGOnDisp);
80 }
81
82 Gtk::TreeModelColumn<Glib::ustring> Filename;
83 Gtk::TreeModelColumn<Glib::ustring> Description;
84 Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > Thumbnail;
85 Gtk::TreeModelColumn<time_t> Time;
86 Gtk::TreeModelColumn<bool> LoadingThumb;
87 Gtk::TreeModelColumn<Glib::ustring> CurBGOnDisp;
88 };
89
90
91 /////////////////////////////////////////////////////////////////////////////
92
93 class Thumbview : public Gtk::ScrolledWindow {
94 public:
95 Thumbview ();
96 ~Thumbview ();
97
98 typedef enum {
99 SORT_ALPHA,
100 SORT_RALPHA,
101 SORT_TIME,
102 SORT_RTIME
103 } SortMode;
104
105 void set_dir(std::string indir) { this->dir = indir; }
106
107 Glib::RefPtr<DelayLoadingStore> store;
108 Gtk::TreeView view;
109 ThumbviewRecord record;
110
111 // dispatcher
112 Glib::Dispatcher dispatch_thumb;
113
114 // thread/idle funcs
115 void load_cache_images();
116 void create_cache_images();
117 void load_dir(std::string dir = "");
118
119 void set_sort_mode (SortMode mode);
120 // search compare function
121 bool search_compare (const Glib::RefPtr<Gtk::TreeModel>& model, int column, const Glib::ustring& key, const Gtk::TreeModel::iterator& iter);
122
123 // loading image
124 Glib::RefPtr<Gdk::Pixbuf> loading_image;
125
126 // "cache" of config - maps displays to full filenames
127 std::map<Glib::ustring, Glib::ustring> map_setbgs;
128 void load_map_setbgs();
129
130 protected:
131
132 #ifdef USE_INOTIFY
133 void file_deleted_callback(std::string filename);
134 void file_changed_callback(std::string filename);
135 void file_created_callback(std::string filename);
136 std::map<std::string, Inotify::Watch*> watches;
137 #endif
138
139 void add_file(std::string filename);
140 void handle_dispatch_thumb();
141
142 Gtk::TreeViewColumn *col_thumb;
143 Gtk::TreeViewColumn *col_desc;
144
145 Gtk::CellRendererPixbuf rend_img;
146 Gtk::CellRendererText rend;
147
148 // utility functions
149 bool is_image(std::string file);
150 Glib::ustring cache_file(Glib::ustring file);
151 void update_thumbnail(Glib::ustring file, Gtk::TreeModel::iterator iter, Glib::RefPtr<Gdk::Pixbuf> pb);
152
153 // base dir
154 // TODO: remove when we get a proper db
155 std::string dir;
156
157 // load thumbnail queue
158 GAsyncQueue* aqueue_loadthumbs;
159 GAsyncQueue* aqueue_createthumbs;
160 GAsyncQueue* aqueue_donethumbs;
161
162 };
This page took 0.038796 seconds and 4 git commands to generate.