jigdo API
Last update by Admin on 2010-05-23
gtk/joblist.hh
Go to the documentation of this file.00001 /* $Id: joblist.hh,v 1.5 2003/08/15 11:38:30 atterer Exp $ -*- C++ -*- 00002 __ _ 00003 |_) /| Copyright (C) 2001-2003 | richard@ 00004 | \/¯| Richard Atterer | atterer.net 00005 ¯ '` ¯ 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License, version 2. See 00008 the file COPYING for details. 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; // = progress report update interval 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 // GTK+ timeout function: calls tick() on stored JobLine objects 00142 static gint timeoutCallback(gpointer jobList); 00143 // GTK+ callback function, called when a line in the list is selected 00144 static gboolean selectRowCallback(GtkTreeSelection*, GtkTreeModel*, 00145 GtkTreePath*, gboolean, gpointer); 00146 /* Function registered with GTK+, sets up pixbuf with progress bar in the 00147 GtkTreeView. */ 00148 static void pixbufForJobLine(GtkTreeViewColumn*, GtkCellRenderer* cell, 00149 GtkTreeModel*, GtkTreeIter* iter, 00150 gpointer data); 00151 // Load file with progress bar images, prepare it for display 00152 static void pixbufForJobLine_init(); 00153 // Helper for prepend() 00154 static gboolean progressScrollToTop(gpointer view); 00155 // Set selectRowIdleId to 0 00156 static gboolean selectRowIdle(gpointer data); 00157 00158 /* Used by initAfterGtk(): Nr of pixbufs to subdivide the progress XPM 00159 into, filename to load from. */ 00160 static const unsigned PROGRESS_SUBDIV = 61; 00161 static const char* const PROGRESS_IMAGE_FILE; 00162 static GdkPixbuf* progressImage; // Pixel data 00163 static vector<GdkPixbuf*> progressGfx; // sub-GdkPixbufs of progressImage 00164 static GValue progressValue; 00165 00166 GtkTreeStore* storeVal; // GTK store of the displayed list 00167 00168 unsigned sizeVal; // Number of rows in table 00169 unsigned entryCountVal; // Number of entries (= sizeVal - nr_of_empty_rows) 00170 JobLine* windowOwnerValue; 00171 00172 /* Count the number of entries in the list which are in a state in which 00173 they need tick() calls. */ 00174 int needTicks; 00175 int timeoutId; // as returned by gtk_timeout_add() 00176 00177 // Callback avoids mult. calls to entries' selectRow() 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 // Mustn't access widgets here because GTK+ is not initialized yet! 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); // 0 => no text initially 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 /* No further action is required. The timeout function will unregister itself 00239 next time it is called, by returning FALSE. */ 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
Generated on Tue Sep 23 14:27:41 2008 for jigdo by
