00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00017 #ifndef JOBLIST_HH
00018 #define JOBLIST_HH
00019
00020 #include <config.h>
00021
00022 #include <string>
00023 #include <vector>
00024 #if DEBUG
00025 # include <iostream>
00026 #endif
00027
00028 #include <debug.hh>
00029 #include <download.hh>
00030 #include <gui.hh>
00031 #include <jobline.fh>
00032 #include <log.hh>
00033 #include <nocopy.hh>
00034
00035
00041 class JobList : NoCopy {
00042 public:
00043 enum {
00045 COLUMN_STATUS,
00047 COLUMN_OBJECT,
00049 COLUMN_DATA,
00051 NR_OF_COLUMNS
00052 };
00053 static const int WIDTH_STATUS = 280;
00054
00057 static const int TICK_INTERVAL = 250;
00058
00059 LOCAL_DEBUG_UNIT_DECL;
00060
00061 typedef unsigned size_type;
00062 inline JobList();
00064 ~JobList();
00067 void finalize();
00068
00071 inline GtkTreeStore* store() const;
00076 inline GtkTreeView* view() const;
00077
00079 inline size_type size() const;
00081 inline size_type entryCount() const;
00082 inline bool empty() const;
00083
00085 inline JobLine* get(GtkTreeIter* row) const;
00087 inline void set(size_type n, JobLine* j);
00090 void erase(GtkTreeIter* row);
00093 inline void insert(size_type n, JobLine* j);
00097 void prepend(JobLine* j, JobLine* parent = 0);
00101 void append(JobLine* j, JobLine* parent = 0);
00104 void makeRowBlank(GtkTreeIter* row);
00105
00112 inline void setWindowOwner(JobLine* j);
00115 inline bool isWindowOwner(JobLine* j) const;
00119 inline JobLine* windowOwner() const;
00120
00127 inline void registerTicks();
00128 inline void unregisterTicks();
00129
00132 void postGtkInit();
00133 # if DEBUG
00134
00135 void assertValid() const;
00136 # else
00137 void assertValid() const { }
00138 # endif
00139
00140 private:
00141
00142 static gint timeoutCallback(gpointer jobList);
00143
00144 static gboolean selectRowCallback(GtkTreeSelection*, GtkTreeModel*,
00145 GtkTreePath*, gboolean, gpointer);
00146
00147
00148 static void pixbufForJobLine(GtkTreeViewColumn*, GtkCellRenderer* cell,
00149 GtkTreeModel*, GtkTreeIter* iter,
00150 gpointer data);
00151
00152 static void pixbufForJobLine_init();
00153
00154 static gboolean progressScrollToTop(gpointer view);
00155
00156 static gboolean selectRowIdle(gpointer data);
00157
00158
00159
00160 static const unsigned PROGRESS_SUBDIV = 61;
00161 static const char* const PROGRESS_IMAGE_FILE;
00162 static GdkPixbuf* progressImage;
00163 static vector<GdkPixbuf*> progressGfx;
00164 static GValue progressValue;
00165
00166 GtkTreeStore* storeVal;
00167
00168 unsigned sizeVal;
00169 unsigned entryCountVal;
00170 JobLine* windowOwnerValue;
00171
00172
00173
00174 int needTicks;
00175 int timeoutId;
00176
00177
00178 unsigned selectRowIdleId;
00179 };
00180
00181
00183 namespace GUI {
00184 extern JobList jobList;
00185 }
00186
00187
00188
00189 JobList::JobList() : storeVal(0), sizeVal(0), entryCountVal(0),
00190 windowOwnerValue(0), needTicks(0),
00191 selectRowIdleId(0) {
00192
00193 }
00194
00195 JobList::size_type JobList::size() const { return sizeVal; }
00196 bool JobList::empty() const { return sizeVal == 0; }
00197 JobList::size_type JobList::entryCount() const { return entryCountVal; }
00198 GtkTreeStore* JobList::store() const { return storeVal; }
00199 GtkTreeView* JobList::view() const {
00200 return GTK_TREE_VIEW(GUI::window.jobs);
00201 }
00202
00203 JobLine* JobList::get(GtkTreeIter* row) const {
00204 gpointer ptr;
00205 gtk_tree_model_get(GTK_TREE_MODEL(store()), row, COLUMN_DATA, &ptr, -1);
00206 return static_cast<JobLine*>(ptr);
00207 }
00208 #if 0
00209 Job* JobList::get(size_type n) {
00210 return static_cast<JobLine*>(gtk_clist_get_row_data(list(), n));
00211 }
00212 void JobList::set(size_type n, JobLine* j) {
00213 gtk_clist_unselect_row(list(), n, 0);
00214 gtk_clist_set_row_data(list(), n, j);
00215 if (j) {
00216 j->jobVec = this;
00217 j->rowVal = n;
00218 }
00219 }
00220 void JobList::insert(size_type n, JobLine* j) {
00221 Paranoid(j != 0);
00222 gtk_clist_insert(list(), n, noText);
00223 gtk_clist_set_row_data(list(), n, j);
00224 ++sizeVal;
00225 ++entryCountVal;
00226 j->jobVec = this;
00227 j->rowVal = n;
00228 j->run();
00229 }
00230 #endif
00231
00232 void JobList::registerTicks() {
00233 if (++needTicks == 1) {
00234 timeoutId = g_timeout_add(TICK_INTERVAL, timeoutCallback, this);
00235 }
00236 debug("registerTicks: %1", needTicks);
00237 }
00238
00239
00240 void JobList::unregisterTicks() {
00241 if (--needTicks == 0)
00242 g_source_remove(timeoutId);
00243 debug("unregisterTicks: %1", needTicks);
00244 }
00245
00246 void JobList::setWindowOwner(JobLine* j) { windowOwnerValue = j; }
00247 bool JobList::isWindowOwner(JobLine* j) const { return windowOwnerValue==j; }
00248 JobLine* JobList::windowOwner() const { return windowOwnerValue; }
00249
00250 #endif