00001 /*************************************************************************** 00002 * Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider, * 00003 * Matthias Hardt, Guido Madaus * 00004 * * 00005 * Copyright (C) 2007-2008 BerLinux Solutions GbR * 00006 * Stefan Schwarzer & Guido Madaus * 00007 * * 00008 * Copyright (C) 2009-2013 BerLinux Solutions GmbH * 00009 * * 00010 * Authors: * 00011 * Stefan Schwarzer <stefan.schwarzer@diskohq.org>, * 00012 * Matthias Hardt <matthias.hardt@diskohq.org>, * 00013 * Jens Schneider <jens.schneider@diskohq.org>, * 00014 * Guido Madaus <guido.madaus@diskohq.org>, * 00015 * Patrick Helterhoff <patrick.helterhoff@diskohq.org>, * 00016 * René Bählkow <rene.baehlkow@diskohq.org> * 00017 * * 00018 * This library is free software; you can redistribute it and/or * 00019 * modify it under the terms of the GNU Lesser General Public * 00020 * License version 2.1 as published by the Free Software Foundation. * 00021 * * 00022 * This library is distributed in the hope that it will be useful, * 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00025 * Lesser General Public License for more details. * 00026 * * 00027 * You should have received a copy of the GNU Lesser General Public * 00028 * License along with this library; if not, write to the * 00029 * Free Software Foundation, Inc., * 00030 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00031 **************************************************************************/ 00032 00033 #include "mmsgui/mmsimagewidgetthread.h" 00034 00035 MMSImageWidgetThread::MMSImageWidgetThread(MMSImageWidget *image) { 00036 this->image = image; 00037 this->inWait = false; 00038 this->stopThread = false; 00039 this->pauseThread = false; 00040 } 00041 00042 void MMSImageWidgetThread::wait(unsigned int delaytime) { 00043 this->inWait = true; 00044 usleep(delaytime); 00045 while (this->pauseThread) 00046 usleep(1000); 00047 this->inWait = false; 00048 } 00049 00050 void MMSImageWidgetThread::stop() { 00051 while (!this->inWait) 00052 usleep(1000); 00053 this->stopThread = true; 00054 } 00055 00056 void MMSImageWidgetThread::pause(bool pauseThread) { 00057 if (pauseThread) { 00058 while (!this->inWait) 00059 usleep(1000); 00060 this->pauseThread = true; 00061 } 00062 else { 00063 this->pauseThread = false; 00064 } 00065 } 00066 00067 void MMSImageWidgetThread::doIt() { 00068 00069 /* init */ 00070 this->inWait = false; 00071 this->stopThread = false; 00072 this->pauseThread = false; 00073 00074 while (1) { 00075 /* first check if the window is shown */ 00076 MMSWindow *win = this->image->getRootWindow(); 00077 if (!win) { 00078 wait(1000000); 00079 if (this->stopThread) 00080 return; 00081 else 00082 continue; 00083 } 00084 if (!win->isShown()) { 00085 wait(1000000); 00086 if (this->stopThread) 00087 return; 00088 else 00089 continue; 00090 } 00091 00092 /* get the next sleep time */ 00093 unsigned int delaytime = 1000; 00094 bool changed = false; 00095 00096 if (image->isActivated()) { 00097 if (image->isSelected()) { 00098 if ((image->selimage)&&(image->selimage_suf)) { 00099 if (image->selimage_suf[image->selimage_curr_index].delaytime > 0) { 00100 /* save current index */ 00101 unsigned int index = image->selimage_curr_index; 00102 00103 /* wait of image */ 00104 int s = 10*1000; 00105 while (image->selimage_suf[image->selimage_curr_index+1].delaytime == MMSIM_DESC_SUF_LOADING) { 00106 wait(s); 00107 if (this->stopThread) 00108 return; 00109 if (s < 100*1000) 00110 s+= 10*1000; 00111 if (!image->selimage_suf) 00112 /* image was deleted!!! */ 00113 break; 00114 } 00115 00116 if (image->selimage_suf) { 00117 /* get next index */ 00118 if (image->selimage_suf[image->selimage_curr_index+1].delaytime == MMSIM_DESC_SUF_END) 00119 /* go back to the beginning */ 00120 image->selimage_curr_index = 0; 00121 else 00122 /* next image */ 00123 image->selimage_curr_index++; 00124 00125 /* check if changed */ 00126 changed = (index != image->selimage_curr_index); 00127 00128 /* get the delaytime */ 00129 delaytime = image->selimage_suf[image->selimage_curr_index].delaytime; 00130 } 00131 } 00132 } 00133 } 00134 else { 00135 if ((image->image)&&(image->image_suf)) { 00136 if (image->image_suf[image->image_curr_index].delaytime > 0) { 00137 /* save current index */ 00138 unsigned int index = image->image_curr_index; 00139 00140 /* wait of image */ 00141 int s = 10*1000; 00142 while (image->image_suf[image->image_curr_index+1].delaytime == MMSIM_DESC_SUF_LOADING) { 00143 wait(s); 00144 if (this->stopThread) 00145 return; 00146 if (s < 100*1000) 00147 s+= 10*1000; 00148 if (!image->image_suf) 00149 /* image was deleted!!! */ 00150 break; 00151 } 00152 00153 if (image->image_suf) { 00154 /* get next index */ 00155 if (image->image_suf[image->image_curr_index+1].delaytime == MMSIM_DESC_SUF_END) 00156 /* go back to the beginning */ 00157 image->image_curr_index = 0; 00158 else 00159 /* next image */ 00160 image->image_curr_index++; 00161 00162 /* check if changed */ 00163 changed = (index != image->image_curr_index); 00164 00165 /* get the delaytime */ 00166 delaytime = image->image_suf[image->image_curr_index].delaytime; 00167 } 00168 } 00169 } 00170 } 00171 } 00172 else { 00173 if (image->isSelected()) { 00174 if ((image->selimage_i)&&(image->selimage_i_suf)) { 00175 if (image->selimage_i_suf[image->selimage_i_curr_index].delaytime > 0) { 00176 /* save current index */ 00177 unsigned int index = image->selimage_i_curr_index; 00178 00179 /* wait of image */ 00180 int s = 10*1000; 00181 while (image->selimage_i_suf[image->selimage_i_curr_index+1].delaytime == MMSIM_DESC_SUF_LOADING) { 00182 wait(s); 00183 if (this->stopThread) 00184 return; 00185 if (s < 100*1000) 00186 s+= 10*1000; 00187 if (!image->selimage_i_suf) 00188 /* image was deleted!!! */ 00189 break; 00190 } 00191 00192 if (image->selimage_i_suf) { 00193 /* get next index */ 00194 if (image->selimage_i_suf[image->selimage_i_curr_index+1].delaytime == MMSIM_DESC_SUF_END) 00195 /* go back to the beginning */ 00196 image->selimage_i_curr_index = 0; 00197 else 00198 /* next image */ 00199 image->selimage_i_curr_index++; 00200 00201 /* check if changed */ 00202 changed = (index != image->selimage_i_curr_index); 00203 00204 /* get the delaytime */ 00205 delaytime = image->selimage_i_suf[image->selimage_i_curr_index].delaytime; 00206 } 00207 } 00208 } 00209 } 00210 else { 00211 if ((image->image_i)&&(image->image_i_suf)) { 00212 if (image->image_i_suf[image->image_i_curr_index].delaytime > 0) { 00213 /* save current index */ 00214 unsigned int index = image->image_i_curr_index; 00215 00216 /* wait of image */ 00217 int s = 10*1000; 00218 while (image->image_i_suf[image->image_i_curr_index+1].delaytime == MMSIM_DESC_SUF_LOADING) { 00219 wait(s); 00220 if (this->stopThread) 00221 return; 00222 if (s < 100*1000) 00223 s+= 10*1000; 00224 if (!image->image_i_suf) 00225 /* image was deleted!!! */ 00226 break; 00227 } 00228 00229 if (image->image_i_suf) { 00230 /* get next index */ 00231 if (image->image_i_suf[image->image_i_curr_index+1].delaytime == MMSIM_DESC_SUF_END) 00232 /* go back to the beginning */ 00233 image->image_i_curr_index = 0; 00234 else 00235 /* next image */ 00236 image->image_i_curr_index++; 00237 00238 /* check if changed */ 00239 changed = (index != image->image_i_curr_index); 00240 00241 /* get the delaytime */ 00242 delaytime = image->image_i_suf[image->image_i_curr_index].delaytime; 00243 } 00244 } 00245 } 00246 } 00247 } 00248 00249 // refresh the widget 00250 if (changed) { 00251 // refresh is required 00252 this->image->enableRefresh(); 00253 00254 this->image->refresh(); 00255 } 00256 00257 // sleep 00258 if (delaytime > 0) 00259 wait(delaytime*1000); 00260 else 00261 wait(1000000); 00262 if (this->stopThread) 00263 return; 00264 } 00265 } 00266 00267 void MMSImageWidgetThread::threadMain() { 00268 doIt(); 00269 delete this; 00270 } 00271