Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsswitcherthread.cpp

Go to the documentation of this file.
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 "mmscore/mmsswitcher.h"
00034 #include "mmscore/mmsswitcherthread.h"
00035 
00036 /**
00037  * Constructor of main thread
00038  */
00039 MMSSwitcherThread::MMSSwitcherThread(MMSSwitcher *sw, MMSLabelWidget *date_s, MMSLabelWidget *time_s, MMSLabelWidget *date_p, MMSLabelWidget *time_p) :
00040     MMSThread("MMSSwitcherThread"),
00041     mode(0),
00042     curr_date(""),
00043     curr_time(""),
00044     sw(sw),
00045     date_s(date_s),
00046     time_s(time_s),
00047     date_p(date_p),
00048     time_p(time_p),
00049     sleepcnt(10),
00050     invoke_plugin(-1),
00051     plugin_invoked(0),
00052     my_spt(NULL),
00053     preview_shown(false) {
00054 }
00055 
00056 /**
00057  * Constructor for plugin specific access to switcher
00058  *
00059  * This instance is used for the show preview method
00060  * of the plugins.
00061  */
00062 MMSSwitcherThread::MMSSwitcherThread(MMSSwitcher *sw) :
00063     mode(1),
00064     sw(sw) {
00065 }
00066 
00067 void MMSSwitcherThread::invokeShowPreview() {
00068 
00069     /* reset sleep cnt */
00070     this->sleepcnt = 10;
00071 
00072     /* lock me */
00073     this->lock.lock();
00074 
00075     /* save the plugin index */
00076     this->invoke_plugin = this->sw->curr_plugin;
00077     this->plugin_invoked = 0;
00078     this->my_spt = NULL;
00079 
00080     /* unlock me */
00081     this->lock.unlock();
00082 }
00083 
00084 void MMSSwitcherThread::previewShown() {
00085     this->preview_shown = true;
00086 }
00087 
00088 void MMSSwitcherThread::threadMain() {
00089 
00090     if (this->mode == 0) {
00091         unsigned int cnt = 0;
00092 
00093         while (1) {
00094             /* lock me */
00095             this->lock.lock();
00096 
00097             if (cnt % 10 == 0) {
00098                 /* check and update date & time */
00099                 if ((date_s)||(date_p)||(time_s)||(time_p)) {
00100                     string datestr, timestr;
00101                     getCurrentTimeString(NULL, &datestr, &timestr);
00102 
00103                     if (datestr != this->curr_date) {
00104                         this->curr_date = datestr;
00105                         if (date_s) date_s->setText(this->curr_date);
00106                         if (date_p) date_p->setText(this->curr_date);
00107                     }
00108 
00109                     if (timestr.substr(0, 5) != this->curr_time) {
00110                         this->curr_time = timestr.substr(0, 5);
00111                         if (time_s) time_s->setText(this->curr_time);
00112                         if (time_p) time_p->setText(this->curr_time);
00113                     }
00114                 }
00115             }
00116 
00117             if (this->plugin_invoked) {
00118                 if (cnt - this->plugin_invoked >= 3) {
00119 /*                    if (this->sw->curr_previewWin < 0)
00120                         this->sw->waitForPreview->show();*/
00121                     this->plugin_invoked = 0;
00122                 }
00123                 else
00124                     if (this->preview_shown)
00125                         this->plugin_invoked = 0;
00126             }
00127 
00128             if (this->my_spt)
00129                 if (!this->my_spt->isRunning()) {
00130                     /* if the last invoked show preview thread is not running anymore, check of waitForPreview */
00131 /*                  if (!this->sw->waitForPreview->willHide())
00132                         if (this->sw->waitForPreview->isShown()) {
00133                             // the wait for preview window is not removed by the plugin thread
00134                             // therefore i have to display nopreview window
00135                             this->sw->noPreview->show();
00136                         }*/
00137                     this->my_spt = NULL;
00138                 }
00139 
00140             if (this->invoke_plugin >= 0) {
00141                 /* start the showPreviewThread only if it does not running */
00142                 map<int, plugin_data_t *>::iterator i = this->sw->plugins.find(this->invoke_plugin);
00143                 this->invoke_plugin = -1;
00144                 if (i != this->sw->plugins.end()) {
00145                     this->my_spt = i->second->switcher->showPreviewThread;
00146                     this->plugin_invoked = cnt;
00147                     this->preview_shown = false;
00148 
00149                     if (!this->my_spt->isRunning())
00150                         this->my_spt->start();
00151                 }
00152             }
00153 
00154             /* unlock me */
00155             this->lock.unlock();
00156 
00157             /* sleep a little bit */
00158             while (this->sleepcnt > 0) {
00159                 this->sleepcnt--;
00160                 msleep(50);
00161             }
00162             this->sleepcnt = 10;
00163             cnt++;
00164         }
00165     }
00166     else
00167     if (this->mode == 1) {
00168         /* check if i have to call showpreview */
00169         if (this->sw->osdhandler)
00170             this->sw->osdhandler->invokeShowPreview(NULL);
00171         else
00172         if (this->sw->centralhandler)
00173             this->sw->centralhandler->invokeShowPreview(NULL);
00174     }
00175 }
00176 

Generated by doxygen