00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmscore/mmsswitcher.h"
00034 #include "mmscore/mmsswitcherthread.h"
00035
00036
00037
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
00058
00059
00060
00061
00062 MMSSwitcherThread::MMSSwitcherThread(MMSSwitcher *sw) :
00063 mode(1),
00064 sw(sw) {
00065 }
00066
00067 void MMSSwitcherThread::invokeShowPreview() {
00068
00069
00070 this->sleepcnt = 10;
00071
00072
00073 this->lock.lock();
00074
00075
00076 this->invoke_plugin = this->sw->curr_plugin;
00077 this->plugin_invoked = 0;
00078 this->my_spt = NULL;
00079
00080
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
00095 this->lock.lock();
00096
00097 if (cnt % 10 == 0) {
00098
00099 if ((date_s)||(date_p)||(time_s)||(time_p)) {
00100 string datestr, timestr;
00101 getCurrentTimeString(NULL, &datestr, ×tr);
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
00120
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
00131
00132
00133
00134
00135
00136
00137 this->my_spt = NULL;
00138 }
00139
00140 if (this->invoke_plugin >= 0) {
00141
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
00155 this->lock.unlock();
00156
00157
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
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