source: vtool/Vtool/vtool.cpp @ bf223ea

Revision bf223ea, 33.5 KB checked in by Tarmo Kople <tarmo@…>, 7 years ago (diff)

Reset dialog new text

  • Property mode set to 100755
Line 
1#include <QPropertyAnimation>
2#include <QSignalMapper>
3#include <QStyle>
4#include <QDesktopWidget>
5#include <QDebug>
6#include <QMessageBox>
7#include <QDateTime>
8#include <QMovie>
9#include <QProcess>
10#include "vtool.h"
11#include "ui_vtool.h"
12#include "irccaptwidget.h"
13#include <vcomm.h>
14#include <vpoller.h>
15#include <updatechecker.h>
16#include <QSharedMemory>
17#include <QMap>
18#include <QThread>
19#include "config.h"
20
21vconfig_t vconfig;
22
23Vtool::Vtool(QWidget *parent) :
24    QMainWindow(parent), ui(new Ui::Vtool)
25
26{
27    ui->setupUi(this);
28
29
30
31#ifdef WIN32
32    // Post upgrade actions
33    QFile vCopyDist;
34    if(vCopyDist.exists("Vcopy.exe.dist")){
35        vCopyDist.remove("Vcopy.exe");
36        vCopyDist.rename("Vcopy.exe.dist", "Vcopy.exe");
37    }
38#endif
39
40    vhandle = NULL;
41    dialogCfg = NULL;
42    poller = NULL;
43    updateFlag = false;
44    appChecker = NULL;
45
46    qMemSet(&vconfig, 0x00, sizeof(vconfig));
47
48    ui->menuBar->setHidden(true);
49    ui->mainToolBar->setHidden(true);
50
51    qApp->setAttribute(Qt::AA_DontUseNativeMenuBar);
52
53
54    setFixedSize(geometry().width(),geometry().height());
55    setWindowTitle(tr("IRvoodoo configurator VoodooTool"));
56
57    this->setGeometry(
58                QStyle::alignedRect(
59                    Qt::LeftToRight,
60                    Qt::AlignCenter,
61                    this->size(),
62                    qApp->desktop()->availableGeometry()
63                    ));
64
65    uix = geometry().width();
66    uiy = geometry().height();
67    btnsize = 148;
68
69#ifdef linux
70    // Hide some unneeded menu items
71    ui->actionCheck_installed_application->setVisible(false);
72    ui->actionVersion->setVisible(false);
73#endif
74
75    loadConfig();
76    OpenIRVoodoo();
77
78}
79
80Vtool::~Vtool()
81{
82    delete ui;
83
84    if(vhandle){
85        // cleanup, Enter normal mode - only if irvoodoo is connected
86        Vset_mode(&vhandle, REQ_SET_MODE_NORMAL);
87        Vclose(&vhandle);
88    }
89
90    QFile::remove(QDir::tempPath() + "/irvoodoo.lock");
91
92    if(updateFlag){
93#ifdef WIN32
94        // win32 only
95        // copy newly downloaded files from download dir to application dir
96        qDebug() << "starting update";
97        QProcess *vupdater = new QProcess();
98        QString vtool_app(qApp->applicationDirPath() + "/Vcopy.exe");
99        vupdater->startDetached(vtool_app);
100#endif
101#ifdef __APPLE__
102        QStringList downloadedFiles = downloader->getDownloadedfiles();
103        QString fname;
104        QString approot = QApplication::applicationDirPath().remove("Contents/MacOS");
105        foreach (fname, downloadedFiles) {
106            qDebug() << "Updating file: " << fname;
107            QFile::remove(approot + fname);
108            QFile::rename(approot + fname + ".dist", approot + fname);
109            if(fname.endsWith("VoodooTool") || fname.endsWith("Vupdater") || fname.endsWith("libvcomm.so")){
110                qDebug() << "Fixing executable bit  ";
111                QFile::setPermissions(approot + fname, QFile::ExeOwner | QFile::ExeOther | QFile::ExeGroup | QFile::ReadOwner |
112                                                  QFile::ReadGroup | QFile::ReadOther | QFile::WriteOwner);
113            }
114        }
115#endif
116    }
117}
118
119void Vtool::OpenIRVoodoo()
120{
121    ui->stackedWidget->setCurrentIndex(PAGE_HOME);
122    int resp = Vopen(&vhandle, (char *)NULL);
123
124    if(resp){
125        ui->stackedWidget->setCurrentIndex(PAGE_FIND_IRVOODOO);
126        QMovie *movie = new QMovie(":/images/search.gif");
127        ui->lbl_find->setMovie(movie);
128        movie->start();
129
130        // create poller, connect rady signal and start polling for IRvoodoo
131        if(!poller){
132            poller = new Vpoller(this);
133            connect(poller, SIGNAL(ready()), this, SLOT(OpenIRVoodoo()));
134            poller->start();
135            return;
136        }
137    }
138
139    QString fwversion;
140    vconfig.fwVersionCurrent = Vtest(&vhandle);
141
142    fwversion.sprintf("FW: %d", vconfig.fwVersionCurrent);
143    QDateTime timestamp;
144    timestamp.setTime_t(vconfig.fwVersionCurrent);
145    ui->lblFW->setText(
146                QString::number(vconfig.fwVersionCurrent) + " "
147                + timestamp.toString(Qt::SystemLocaleDate));
148
149    hwid_t mcu_id;
150    Vget_id(&vhandle, &mcu_id);
151    voodooSerial.sprintf("%08X-%08X-%08X-%08X", mcu_id.serial[3], mcu_id.serial[2],
152                         mcu_id.serial[1], mcu_id.serial[0]);
153    ui->lblUUID->setText(voodooSerial);
154    if (mcu_id.pid == 0x2980002B) {
155        ui->lblID->setText("LPC11U24FBD48/401");
156    } else {
157        ui->lblID->setText("unknown");
158    }
159
160    goHome(tr("IRvoodoo Ready !"));
161    updChecker = new UpdateChecker(this, UPDATE_SITE, voodooSerial);
162    connect(updChecker, SIGNAL(Ready(bool)), this, SLOT(NewFwCheck(bool)));
163
164
165
166}
167
168void Vtool::NewFwCheck(bool status)
169{
170    if(status){
171        QVariantMap versionMap;
172        versionMap = updChecker->getVersionMap();
173        vconfig.fwVersionAvailable = versionMap["firmware"].toInt();
174
175        if(vconfig.fwVersionAvailable > vconfig.fwVersionCurrent){
176            ui->statusBar->showMessage(tr("New firmware available. Please update !"), 15000);
177        }
178#ifdef WIN32
179        else{
180            qDebug() << "Version map " << versionMap;
181            vconfig.appVersionAvailable = (versionMap["app_win32"]).toInt();
182            qDebug() << "App current: " << vconfig.appVersionCurrent;
183            qDebug() << "App available: " << vconfig.appVersionAvailable;
184            if((vconfig.appVersionCurrent > 0) && (vconfig.appVersionAvailable > vconfig.appVersionCurrent)){
185                ui->statusBar->showMessage(tr("Downloading Application updates"), 15000);
186                downloader = new Appdownloader(UPDATE_SITE, qApp->applicationDirPath(), voodooSerial);
187                connect(downloader, SIGNAL(Ready(bool)), this, SLOT(downloaderFinished(bool)));
188                downloader->downloadApp(vconfig.appVersionAvailable);
189            }
190        }
191#endif
192#ifdef __APPLE__
193        qDebug() << "Version map " << versionMap;
194        vconfig.appVersionAvailable = (versionMap["app_osx32"]).toInt();
195        qDebug() << "App current: " << vconfig.appVersionCurrent;
196        qDebug() << "App available: " << vconfig.appVersionAvailable;
197        if((vconfig.appVersionCurrent > 0) && (vconfig.appVersionAvailable > vconfig.appVersionCurrent)){
198            ui->statusBar->showMessage(tr("Downloading Application updates"), 15000);
199            downloader = new Appdownloader(UPDATE_SITE, qApp->applicationDirPath().remove("Contents/MacOS"), voodooSerial);
200            connect(downloader, SIGNAL(Ready(bool)), this, SLOT(downloaderFinished(bool)));
201            downloader->downloadApp(vconfig.appVersionAvailable);
202        }
203#endif
204    }else{
205        qDebug() << "New FW check failed " << updChecker->errorString();
206    }
207}
208
209
210void Vtool::downloaderFinished(bool status)
211{
212    if(status){
213        updateFlag = true;
214        ui->statusBar->showMessage(tr("Updates downloaded, Please restart application!"), 15000);
215    }
216}
217
218
219/*
220 *  Navigation
221 */
222void Vtool::on_btnAddEvent_clicked()
223{
224    ui->stackedWidget->setCurrentIndex(PAGE_ADD_EVENT);
225}
226
227void Vtool::on_btnDeleteEvent_clicked()
228{
229    ui->stackedWidget->setCurrentIndex(PAGE_DELETE_EVENT);
230}
231
232void Vtool::goHome(QString message)
233{
234#ifdef __APPLE__
235    ui->actionBackup_configuration->setDisabled(true);
236    ui->actionCheck_installed_application->setDisabled(true);
237    ui->actionExit->setDisabled(true);
238    ui->actionFactory_reset->setDisabled(true);
239    ui->actionIR_Frame_viewer->setDisabled(true);
240    ui->actionQT_version->setDisabled(true);
241    ui->actionRestore_configuration->setDisabled(true);
242    ui->actionSettings->setDisabled(true);
243    ui->actionShow_eventmap->setDisabled(true);
244    ui->actionTest_Remote->setDisabled(true);
245    ui->actionUpdate_Firmware->setDisabled(true);
246    ui->actionVersion->setDisabled(true);
247#endif
248
249    ui->lbl_msg_home->setText(message);
250
251    ui->lbl_msg_keyboardKontrols->setText("");
252    ui->lbl_msg_mouseControls->setText("");
253    ui->lbl_msg_mediaControls->setText("");
254    ui->lbl_msg_page_irCapture->setText("");
255
256    ui->mainToolBar->setHidden(true);
257    ui->menuBar->setHidden(true);
258
259    Vset_mode(&vhandle, REQ_SET_MODE_NORMAL);
260
261    ui->CaptWidget->stopCapture();
262
263    disconnect(ui->CaptWidget, 0, 0, 0);
264    disconnect(ui->KeyboardControls, 0, 0,0);
265    disconnect(ui->MouseControls, 0, 0,0);
266    disconnect(ui->MediaControls, 0, 0,0);
267    ui->btn_page_irscan_ok->setHidden(true);
268
269    disconnect(ui->btn_page_irscan_ok, 0, 0, 0);
270    disconnect(ui->btn_page_irscan_back, 0, 0, 0);
271
272    ui->stackedWidget->setCurrentIndex(PAGE_HOME);
273    ui->btnAddEvent->setFocus();
274}
275
276
277/*
278 * ============= add KEYBOARD event =========================
279 */
280void Vtool::on_btnAddKeyboardEvent_clicked()
281{
282    ui->lbl_action_keyboard_controls->setPixmap(QPixmap(":/images/add_event.png"));
283    ui->stackedWidget->setCurrentIndex(PAGE_KEYBOARD_CONTROLS);
284    ui->KeyboardControls->setFocus();
285    connect(ui->KeyboardControls, SIGNAL(ready()), this, SLOT(KBkeySelected()));
286    //    ui->KeyboardControls->clear();
287    ui->KeyboardControls->start();
288}
289
290void Vtool::KBkeySelected()
291{
292    disconnect(ui->KeyboardControls, SIGNAL(ready()), 0, 0);
293    ui->CaptWidget->setText("Press button on the remote control");
294    ui->stackedWidget->setCurrentIndex(PAGE_IR_SCAN);
295    ui->btn_page_irscan_back->setHidden(true);
296    connect(ui->CaptWidget, SIGNAL(ready(int)), this, SLOT(KBremoteButtonSelected(int)));
297    ui->CaptWidget->startCapture(vhandle);
298}
299
300void Vtool::KBremoteButtonSelected(int res)
301{
302    disconnect(ui->CaptWidget, SIGNAL(ready(int)), 0,0);
303    if(res == IrcCaptWidget::capt_cancel  || res == IrcCaptWidget::capt_com_err){
304        goHome();
305    }else if(res == IrcCaptWidget::capt_ok){
306
307        // Ok, add keyboard event;
308        cmdstat_t cmdstat;  // command status struct
309        ircode_t keyboardIRcode, remoteIRcode;
310
311        keyboardIRcode = ui->KeyboardControls->getIRcode();
312        remoteIRcode = ui->CaptWidget->getIRcode();
313        Vset_event(&vhandle, &remoteIRcode, &keyboardIRcode, &cmdstat);
314        //        ui->KeyboardControls->clear();
315        if(cmdstat.type == RESP_OK){
316            ui->CaptWidget->setText(tr("New keyboard event succesfully added!"));
317        }else{
318            if(cmdstat.err_code == ERR_EVENTMAP_FULL){
319                ui->CaptWidget->setText(tr("Error ! IRvoodoo memory full!"));
320            }else{
321                ui->CaptWidget->setText(tr("Error ! Unknown error!"));
322            }
323        }
324    }
325    connect(ui->btn_page_irscan_back, SIGNAL(clicked()), this, SLOT(on_btnAddKeyboardEvent_clicked()));
326    ui->btn_page_irscan_back->setVisible(true);
327    ui->btn_page_irscan_back->setFocus();
328}
329
330
331/*
332 * ============= add MOUSE event =========================
333 */
334
335void Vtool::on_btnAddMouseEvent_clicked()
336{
337    connect(ui->MouseControls, SIGNAL(ready()), this, SLOT(mouseControlSelected()));
338    ui->lbl_action_mouse_controls->setPixmap(QPixmap(":/images/add_event.png"));
339    ui->stackedWidget->setCurrentIndex(PAGE_MOUSE_CONTROLS);
340}
341
342void Vtool::mouseControlSelected(){
343
344    connect(ui->CaptWidget, SIGNAL(ready(int)), this, SLOT(mouseRemoteButtonSelected(int)));
345    ui->btn_page_irscan_back->setHidden(true);
346    ui->CaptWidget->setText("Press button on the remote control");
347    ui->stackedWidget->setCurrentIndex(PAGE_IR_SCAN);
348    ui->CaptWidget->startCapture(vhandle);
349}
350
351void Vtool::mouseRemoteButtonSelected(int res)
352{
353
354    disconnect(ui->CaptWidget, SIGNAL(ready(int)), this, SLOT(mouseRemoteButtonSelected(int)));
355
356    if(res == IrcCaptWidget::capt_cancel  || res == IrcCaptWidget::capt_com_err){
357        ui->stackedWidget->setCurrentIndex(PAGE_HOME);
358    }else if(res == IrcCaptWidget::capt_ok){
359
360        // Ok, add mouse event;
361        cmdstat_t cmdstat;  // command status struct
362        ircode_t mouseIRcode, remoteIRcode;
363
364        remoteIRcode = ui->CaptWidget->getIRcode();
365        mouseIRcode = ui->MouseControls->getIRcode();
366
367        Vset_event(&vhandle, &remoteIRcode, &mouseIRcode, &cmdstat);
368
369        if(cmdstat.type == RESP_OK){
370            ui->CaptWidget->setText(tr("New mouse event succesfully added!"));
371        }else{
372            if(cmdstat.err_code == ERR_EVENTMAP_FULL){
373                ui->CaptWidget->setText(tr("Error ! IRvoodoo memory full!"));
374            }else{
375                ui->CaptWidget->setText(tr("Error ! Unknown error!"));
376            }
377        }
378    }
379    connect(ui->btn_page_irscan_back, SIGNAL(clicked()), this, SLOT(on_btnAddMouseEvent_clicked()));
380    ui->btn_page_irscan_back->setVisible(true);
381    ui->btn_page_irscan_back->setFocus();
382}
383
384/*
385 * ============= add MEDIA event =========================
386 */
387void Vtool::on_btnAddMediaEvent_clicked()
388{
389    disconnect(ui->btn_page_irscan_back, SIGNAL(clicked()), 0,0);
390    connect(ui->MediaControls, SIGNAL(ready()), this, SLOT(mediaControlSelected()));
391    ui->lbl_action_media_controls->setPixmap(QPixmap(":/images/add_event.png"));
392    ui->stackedWidget->setCurrentIndex(PAGE_MEDIA_CONTROLS);
393}
394
395void Vtool::mediaControlSelected()
396{
397    disconnect(ui->MediaControls, SIGNAL(ready()), 0,0);
398    connect(ui->CaptWidget, SIGNAL(ready(int)), this, SLOT(mediaRemoteButtonSelected(int)));
399    ui->btn_page_irscan_back->setHidden(true);
400    ui->CaptWidget->setText(tr("Press button on the remote control"));
401    ui->stackedWidget->setCurrentIndex(PAGE_IR_SCAN);
402    ui->CaptWidget->startCapture(vhandle);
403}
404
405void Vtool::mediaRemoteButtonSelected(int res)
406{
407    disconnect(ui->CaptWidget, SIGNAL(ready(int)), 0,0);
408
409    if(res == IrcCaptWidget::capt_cancel  || res == IrcCaptWidget::capt_com_err){
410        ui->stackedWidget->setCurrentIndex(PAGE_HOME);
411    }else if(res == IrcCaptWidget::capt_ok){
412
413        // Ok, add keyboard event;
414        cmdstat_t cmdstat;  // command status struct
415        ircode_t mediaIRcode, remoteIRcode;
416
417        remoteIRcode = ui->CaptWidget->getIRcode();
418        mediaIRcode = ui->MediaControls->getIRcode();
419        Vset_event(&vhandle, &remoteIRcode, &mediaIRcode, &cmdstat);
420
421        if(cmdstat.type == RESP_OK){
422            ui->CaptWidget->setText(tr("New media event succesfully added!"));
423        }else{
424            if(cmdstat.err_code == ERR_EVENTMAP_FULL){
425                ui->CaptWidget->setText(tr("Error ! IRvoodoo memory full!"));
426            }else{
427                ui->CaptWidget->setText(tr("Error ! Unknown error!"));
428            }
429        }
430
431    }
432    connect(ui->btn_page_irscan_back, SIGNAL(clicked()), this, SLOT(on_btnAddMediaEvent_clicked()));
433    ui->btn_page_irscan_back->setVisible(true);
434}
435
436/*
437 * ============= add REMOTE->REMOTE event =========================
438 */
439
440void Vtool::on_btnAddIREvent_clicked()
441{
442    ui->btn_page_irscan_back->setHidden(true);
443    connect(ui->CaptWidget, SIGNAL(ready(int)), this, SLOT(remote1Selected(int)));
444    ui->btn_page_irscan_ok->setHidden(true);
445    ui->CaptWidget->setText(tr("Press button on the remote control"));
446    ui->lbl_action_irscan->setPixmap(QPixmap(":/images/add_event.png"));
447    ui->stackedWidget->setCurrentIndex(PAGE_IR_SCAN);
448    ui->CaptWidget->startCapture(vhandle);
449    ui->CaptWidget->setText(tr("button for Remote 1"));
450}
451
452void Vtool::remote1Selected(int res)
453{
454    disconnect(ui->CaptWidget, SIGNAL(ready(int)), 0,0);
455
456    if(res == IrcCaptWidget::capt_cancel  || res == IrcCaptWidget::capt_com_err){
457        ui->stackedWidget->setCurrentIndex(PAGE_HOME);
458    }else if(res == IrcCaptWidget::capt_ok){
459        remot1IRcode = ui->CaptWidget->getIRcode();
460        connect(ui->btn_page_irscan_ok, SIGNAL(clicked()), this, SLOT(on_btn_page_irscan_ok_clicked()));
461        ui->btn_page_irscan_ok->setVisible(true);
462        ui->btn_page_irscan_ok->setFocus();
463    }
464}
465
466void Vtool::on_btn_page_irscan_ok_clicked()
467{
468    ui->btn_page_irscan_ok->setHidden(true);
469    disconnect(ui->btn_page_irscan_ok, SIGNAL(clicked()), 0,0);
470    connect(ui->CaptWidget, SIGNAL(ready(int)), this, SLOT(remote2Selected(int)));
471    ui->CaptWidget->setText(tr("Press button on the remote control"));
472    ui->stackedWidget->setCurrentIndex(PAGE_IR_SCAN);
473    ui->CaptWidget->startCapture(vhandle);
474    ui->CaptWidget->setText(tr("button for Remote 2"));
475
476}
477
478void Vtool::remote2Selected(int res)
479{
480    disconnect(ui->CaptWidget, SIGNAL(ready(int)), 0,0);
481
482    if(res == IrcCaptWidget::capt_cancel  || res == IrcCaptWidget::capt_com_err){
483        ui->stackedWidget->setCurrentIndex(PAGE_HOME);
484    }else if(res == IrcCaptWidget::capt_ok){
485
486        // Ok, add keyboard event;
487        ircode_t remote2IRcode;
488        cmdstat_t cmdstat;  // command status struct
489        remote2IRcode = ui->CaptWidget->getIRcode();
490        Vset_event(&vhandle, &remote2IRcode, &remot1IRcode, &cmdstat);
491
492        if(cmdstat.type == RESP_OK){
493            ui->CaptWidget->setText(tr("New IR event succesfully added!"));
494        }else{
495            if(cmdstat.err_code == ERR_EVENTMAP_FULL){
496                ui->CaptWidget->setText(tr("Error ! IRvoodoo memory full!"));
497            }else{
498                ui->CaptWidget->setText(tr("Error ! Unknown error!"));
499            }
500        }
501    }
502    connect(ui->btn_page_irscan_back, SIGNAL(clicked()), this, SLOT(on_btnAddIREvent_clicked()));
503    ui->btn_page_irscan_back->setVisible(true);
504    ui->btn_page_irscan_back->setFocus();
505
506}
507
508/*
509 * ============= Delete events =========================
510 */
511void Vtool::on_btnDeleteKeyboardEvent_clicked()
512{
513    connect(ui->KeyboardControls, SIGNAL(ready()), this, SLOT(delKeyboardKey()));
514    ui->lbl_action_keyboard_controls->setPixmap(QPixmap(":/images/remove_event.png"));
515    ui->stackedWidget->setCurrentIndex(PAGE_KEYBOARD_CONTROLS);
516    ui->KeyboardControls->setFocus();
517    //    ui->KeyboardControls->clear();
518    ui->KeyboardControls->start();
519}
520
521void Vtool::delKeyboardKey()
522{
523    cmdstat_t cmdstat;
524    disconnect(ui->KeyboardControls, SIGNAL(ready()), 0, 0 );
525    cmdstat = deleteEvent(ui->KeyboardControls->getIRcode());
526    if(cmdstat.type == RESP_OK){
527        ui->lbl_msg_keyboardKontrols->setText(tr("Keyboard event succesfully removed!"));
528    }else{
529        if(cmdstat.err_code == ERR_IRCODE_NOT_FOUND){
530            ui->lbl_msg_keyboardKontrols->setText(tr("Keyboard event not found!"));
531        }else{
532            ui->lbl_msg_keyboardKontrols->setText(tr("Unknown error!"));
533        }
534    }
535    ui->stackedWidget->setCurrentIndex(PAGE_HOME);
536    on_btnDeleteKeyboardEvent_clicked();
537
538}
539
540void Vtool::on_btnDeleteMouseEvent_clicked()
541{
542    connect(ui->MouseControls, SIGNAL(ready()), this, SLOT(delMouseControl()));
543    ui->lbl_action_mouse_controls->setPixmap(QPixmap(":/images/remove_event.png"));
544    ui->stackedWidget->setCurrentIndex(PAGE_MOUSE_CONTROLS);
545}
546
547void Vtool::delMouseControl()
548{
549    cmdstat_t cmdstat;
550    disconnect(ui->MouseControls, SIGNAL(ready()), 0, 0 );
551    cmdstat = deleteEvent(ui->MouseControls->getIRcode());
552    if(cmdstat.type == RESP_OK){
553        ui->lbl_msg_mouseControls->setText(tr("Mouse event succesfully removed!"));
554    }else{
555        if(cmdstat.err_code == ERR_IRCODE_NOT_FOUND){
556            ui->lbl_msg_mouseControls->setText(tr("Mouse event not found!"));
557        }else{
558            ui->lbl_msg_mouseControls->setText(tr("Unknown error!"));
559        }
560    }
561    ui->stackedWidget->setCurrentIndex(PAGE_HOME);
562    on_btnDeleteMouseEvent_clicked();
563}
564
565void Vtool::on_btnDeleteMediaEvent_clicked()
566{
567    connect(ui->MediaControls, SIGNAL(ready()), this, SLOT(delMediaControl()));
568    ui->lbl_action_media_controls->setPixmap(QPixmap(":/images/remove_event.png"));
569    ui->stackedWidget->setCurrentIndex(PAGE_MEDIA_CONTROLS);
570}
571
572void Vtool::delMediaControl()
573{
574    cmdstat_t cmdstat;
575    disconnect(ui->MediaControls, SIGNAL(ready()), 0, 0 );
576    cmdstat = deleteEvent(ui->MediaControls->getIRcode());
577    if(cmdstat.type == RESP_OK){
578        ui->lbl_msg_mediaControls->setText(tr("Media event succesfully removed!"));
579    }else{
580        if(cmdstat.err_code == ERR_IRCODE_NOT_FOUND){
581            ui->lbl_msg_mediaControls->setText(tr("Media event not found!"));
582        }else{
583            ui->lbl_msg_mediaControls->setText(tr("Unknown error!"));
584        }
585    }
586    ui->stackedWidget->setCurrentIndex(PAGE_HOME);
587    on_btnDeleteMediaEvent_clicked();
588
589}
590
591void Vtool::on_btnDeleteIRevent_clicked()
592{
593    connect(ui->CaptWidget, SIGNAL(ready(int)), this, SLOT(delRemoteButton(int)));
594    ui->CaptWidget->setText(tr("Press button on the remote control"));
595    ui->lbl_action_irscan->setPixmap(QPixmap(":/images/remove_event.png"));
596    ui->stackedWidget->setCurrentIndex(PAGE_IR_SCAN);
597    ui->btn_page_irscan_back->setHidden(true);
598    ui->CaptWidget->startCapture(vhandle);
599}
600
601void Vtool::delRemoteButton(int res)
602{
603    disconnect(ui->CaptWidget, SIGNAL(ready(int)), 0, 0 );
604
605    if(res == IrcCaptWidget::capt_cancel  || res == IrcCaptWidget::capt_com_err){
606        ui->stackedWidget->setCurrentIndex(PAGE_HOME);
607        return;
608    }else if(res == IrcCaptWidget::capt_ok){
609
610        ircode_t IRcode;
611        cmdstat_t cmdstat;  // command status struct
612
613        IRcode = ui->CaptWidget->getIRcode();
614        Vclear_event_ircode(&vhandle, &IRcode, &cmdstat);
615
616        if(cmdstat.type == RESP_OK){
617            ui->CaptWidget->setText(tr("IR event succesfully deleted!"));
618        }else{
619            if(cmdstat.err_code == ERR_IRCODE_NOT_FOUND){
620                ui->CaptWidget->setText(tr("No such IR event found!"));
621            }else{
622                ui->CaptWidget->setText(tr("Error ! Unknown error!"));
623            }
624        }
625    }
626    connect(ui->btn_page_irscan_back, SIGNAL(clicked()), this, SLOT(on_btnDeleteIRevent_clicked()));
627    ui->btn_page_irscan_back->setVisible(true);
628}
629
630cmdstat_t Vtool::deleteEvent(ircode_t ircode)
631{
632    disconnect(ui->MediaControls, SIGNAL(ready()), 0, 0 );
633    cmdstat_t cmdstat;  // command status struct
634    Vclear_event_ircode(&vhandle, &ircode, &cmdstat);
635    return cmdstat;
636}
637
638void Vtool::updateEventsInUse(){
639    stat_t st;
640    if(!Vget_stat(&vhandle, &st)){
641        int pr;
642        pr = (100 * st.events_in_use) / st.eventmap_size;
643        ui->progressMemory->setValue(pr);
644        ui->lblMemory->setText(tr("Number of configured events: %1").arg(st.events_in_use));
645    }
646}
647
648void Vtool::on_stackedWidget_currentChanged(int arg1)
649{
650
651    if(arg1 == PAGE_CONFIG){
652#ifdef __APPLE__
653        ui->actionBackup_configuration->setDisabled(false);
654        ui->actionCheck_installed_application->setDisabled(false);
655        ui->actionExit->setDisabled(false);
656        ui->actionFactory_reset->setDisabled(false);
657        ui->actionIR_Frame_viewer->setDisabled(false);
658        ui->actionQT_version->setDisabled(false);
659        ui->actionRestore_configuration->setDisabled(false);
660        ui->actionSettings->setDisabled(false);
661        ui->actionShow_eventmap->setDisabled(false);
662        ui->actionTest_Remote->setDisabled(false);
663        ui->actionUpdate_Firmware->setDisabled(false);
664        ui->actionVersion->setDisabled(false);
665#endif
666        updateEventsInUse();
667        ui->menuBar->setVisible(true);
668        ui->mainToolBar->setVisible(true);
669
670    }else{
671        if(ui->menuBar->isVisible()){
672            ui->menuBar->setHidden(true);
673            ui->mainToolBar->setHidden(true);
674        }
675    }
676
677    animate(arg1);
678
679}
680
681
682void Vtool::animate(int page)
683{
684#define ANIM_SPEED 200
685
686    if(page == PAGE_HOME){
687        QPropertyAnimation *animation = new QPropertyAnimation(ui->btnAddEvent, "geometry");
688        animation->setDuration(ANIM_SPEED);
689        animation->setStartValue(QRect(-btnsize, ui->btnAddEvent->geometry().y(), btnsize, btnsize));
690        animation->setEndValue(ui->btnAddEvent->geometry());
691        animation->start();
692
693        QPropertyAnimation *animation2 = new QPropertyAnimation(ui->btnConfigure, "geometry");
694        animation2->setDuration(ANIM_SPEED);
695        animation2->setEndValue(ui->btnConfigure->geometry());
696        animation2->setStartValue(QRect(uix, ui->btnConfigure->geometry().y(), btnsize, btnsize));
697        animation2->start();
698
699        QPropertyAnimation *animation3 = new QPropertyAnimation(ui->btnDeleteEvent, "geometry");
700        animation3->setDuration(ANIM_SPEED);
701        animation3->setEndValue(ui->btnDeleteEvent->geometry());
702        animation3->setStartValue(QRect(ui->btnDeleteEvent->geometry().x(), -btnsize , btnsize, btnsize));
703        animation3->start();
704    }
705    if(page == PAGE_ADD_EVENT){
706        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->btnAddKeyboardEvent, "geometry");
707        animation1->setDuration(ANIM_SPEED);
708        animation1->setEndValue(ui->btnAddKeyboardEvent->geometry());
709        animation1->setStartValue(QRect(-btnsize, -btnsize, btnsize, btnsize));
710        animation1->start();
711
712        QPropertyAnimation *animation2 = new QPropertyAnimation(ui->btnAddMouseEvent, "geometry");
713        animation2->setDuration(ANIM_SPEED);
714        animation2->setEndValue(ui->btnAddMouseEvent->geometry());
715        animation2->setStartValue(QRect(uix, -btnsize , btnsize, btnsize));
716        animation2->start();
717
718        QPropertyAnimation *animation3 = new QPropertyAnimation(ui->btnAddMediaEvent, "geometry");
719        animation3->setDuration(ANIM_SPEED);
720        animation3->setEndValue(ui->btnAddMediaEvent->geometry());
721        animation3->setStartValue(QRect(-btnsize, uiy, btnsize, btnsize));
722        animation3->start();
723
724        QPropertyAnimation *animation4 = new QPropertyAnimation(ui->btnAddIREvent, "geometry");
725        animation4->setDuration(ANIM_SPEED);
726        animation4->setEndValue(ui->btnAddIREvent->geometry());
727        animation4->setStartValue(QRect(uix, uiy, btnsize, btnsize));
728        animation4->start();
729    }
730    if(page == PAGE_DELETE_EVENT){
731        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->btnDeleteKeyboardEvent, "geometry");
732        animation1->setDuration(ANIM_SPEED);
733        animation1->setEndValue(ui->btnDeleteKeyboardEvent->geometry());
734        animation1->setStartValue(QRect(-btnsize, -btnsize, btnsize, btnsize));
735        animation1->start();
736
737        QPropertyAnimation *animation2 = new QPropertyAnimation(ui->btnDeleteMouseEvent, "geometry");
738        animation2->setDuration(ANIM_SPEED);
739        animation2->setEndValue(ui->btnDeleteMouseEvent->geometry());
740        animation2->setStartValue(QRect(uix, -btnsize , btnsize, btnsize));
741        animation2->start();
742
743        QPropertyAnimation *animation3 = new QPropertyAnimation(ui->btnDeleteMediaEvent, "geometry");
744        animation3->setDuration(ANIM_SPEED);
745        animation3->setEndValue(ui->btnDeleteMediaEvent->geometry());
746        animation3->setStartValue(QRect(-btnsize, uiy, btnsize, btnsize));
747        animation3->start();
748
749        QPropertyAnimation *animation4 = new QPropertyAnimation(ui->btnDeleteIRevent, "geometry");
750        animation4->setDuration(ANIM_SPEED);
751        animation4->setEndValue(ui->btnDeleteIRevent->geometry());
752        animation4->setStartValue(QRect(uix, uiy, btnsize, btnsize));
753        animation4->start();
754    }
755    if (page == PAGE_MOUSE_CONTROLS){
756        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->MouseControls, "geometry");
757        animation1->setDuration(ANIM_SPEED);
758        animation1->setEndValue(ui->MouseControls->geometry());
759        animation1->setStartValue(QRect(ui->MouseControls->geometry().x(), -ui->MouseControls->geometry().height(), ui->MouseControls->geometry().width(), ui->MouseControls->geometry().height()));
760        animation1->start();
761    }
762    if (page == PAGE_IR_SCAN){
763        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->CaptWidget, "geometry");
764        animation1->setDuration(ANIM_SPEED);
765        animation1->setEndValue(ui->CaptWidget->geometry());
766        animation1->setStartValue(QRect(ui->CaptWidget->geometry().x(), -ui->CaptWidget->geometry().height(), ui->CaptWidget->geometry().width(), ui->CaptWidget->geometry().height()));
767        animation1->start();
768    }
769    if (page == PAGE_KEYBOARD_CONTROLS){
770        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->KeyboardControls, "geometry");
771        animation1->setDuration(ANIM_SPEED);
772        animation1->setEndValue(ui->KeyboardControls->geometry());
773        animation1->setStartValue(QRect(ui->KeyboardControls->geometry().x(), -ui->KeyboardControls->geometry().height(), ui->KeyboardControls->geometry().width(), ui->KeyboardControls->geometry().height()));
774        animation1->start();
775    }
776    if (page == PAGE_MEDIA_CONTROLS){
777        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->MediaControls, "geometry");
778        animation1->setDuration(ANIM_SPEED);
779        animation1->setEndValue(ui->MediaControls->geometry());
780        animation1->setStartValue(QRect(ui->MediaControls->geometry().x(), -ui->MediaControls->geometry().height(), ui->MediaControls->geometry().width(), ui->MediaControls->geometry().height()));
781        animation1->start();
782    }
783    if (page == PAGE_CONFIG){
784        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->stackedWidget, "geometry");
785        animation1->setDuration(ANIM_SPEED);
786        animation1->setEndValue(ui->stackedWidget->geometry());
787        animation1->setStartValue(QRect(ui->stackedWidget->geometry().x(), -ui->stackedWidget->geometry().height(), ui->MediaControls->geometry().width(), ui->MediaControls->geometry().height()));
788        animation1->start();
789    }
790}
791
792
793void Vtool::on_btnConfigure_clicked()
794{
795    ui->stackedWidget->setCurrentIndex(PAGE_CONFIG);
796}
797
798
799void Vtool::on_actionIR_Frame_viewer_triggered()
800{
801    FrameViewer *FrameWindow = new FrameViewer(this, vhandle);
802    FrameWindow->show();
803}
804
805void Vtool::on_actionSettings_triggered()
806{
807    if(!dialogCfg) dialogCfg = new DlgCfg(this, vhandle);
808    dialogCfg->LoadConfig();
809    dialogCfg->show();
810}
811
812void Vtool::on_actionFactory_reset_triggered()
813{
814    QMessageBox::StandardButton reply;
815    reply = QMessageBox::critical(this, tr("VoodooTool"),
816                                  tr("Are you sure you want to restore the IRvoodoo to its original settings ? All of your configuration will be erased! Please backup before continuing! "),
817                                  QMessageBox::Yes | QMessageBox::No );
818    if (reply == QMessageBox::Yes){
819        Vclear_eventmap(&vhandle);
820        Vreset_config(&vhandle);
821        QMessageBox::information(this, tr("VoodooTool"),tr("Your IRvoodoo has been restored to its original settings !"));
822        updateEventsInUse();
823    }
824
825}
826
827void Vtool::on_actionUpdate_Firmware_triggered()
828{
829    // remove lock file
830    QFile::remove(QDir::tempPath() + "/irvoodoo.lock");
831
832    QProcess *vupdater = new QProcess();
833    QString vtool_app(qApp->applicationDirPath());
834
835#ifdef WIN32
836    // use VoodooRefresh.exe as updater name instead Vupdater.exe to prevent windows UAC warning
837    vtool_app.append("/VoodooRefresh.exe");
838#else
839    vtool_app.append("/Vupdater");
840#endif
841
842    vupdater->startDetached(vtool_app);
843    qApp->exit();
844}
845
846quint32 Vtool::readLocalAppVersion()
847{
848#ifdef __APPLE__
849    QFile appFile(QApplication::applicationDirPath().remove("MacOS") + "Resources/app.txt") ;
850#else
851    QFile appFile("app.txt");
852#endif
853
854    if(!appFile.open(QIODevice::ReadOnly)){
855        qDebug() << "Cannot open app.txt for version checking";
856        return 0;
857    }
858
859    QTextStream inStream(&appFile);
860    QString line;
861    line = inStream.readLine();
862    appFile.close();
863
864    QStringList columns = line.split('\t');
865    if(columns.count() != 2){
866        qDebug() << "app.txt parse error";
867        return 0;
868    }
869
870    bool ok;
871    quint32 version = columns[1].toInt(&ok, 10);
872    if(!ok){
873        qDebug() << "app.txt parse error";
874        return 0;
875    }
876
877    return version;
878
879}
880
881void Vtool::loadConfig()
882{
883
884
885#ifdef unix
886    vconfig.homeDir =  new QString(QDir::homePath() + "/.IRvoodoo");
887#endif
888#ifdef __APPLE__
889    vconfig.homeDir =  new QString(QDir::homePath() + "/.IRvoodoo");
890#endif
891#ifdef WIN32
892    //win32
893    vconfig.homeDir = new QString(QDir::homePath() + "/IRvoodoo");
894#endif
895    QDir vdir = QDir(*vconfig.homeDir);
896    if(!vdir.exists(*vconfig.homeDir)){
897        vdir.mkpath(*vconfig.homeDir);
898    }
899
900    settings = new QSettings("FlyCom", "VoodooTool");
901    vconfig.appVersionCurrent = readLocalAppVersion();
902
903    if(!vconfig.appVersionCurrent){
904        qDebug() << "Cannot get local app version, aborting version checks";
905        return;
906    }
907    vconfig.appVersionLast = settings->value("appVersionLast").toInt();
908
909    // new config ? first run ?
910    if(!vconfig.appVersionLast){
911        vconfig.appVersionLast = vconfig.appVersionCurrent;
912        settings->setValue("appVersionLast", vconfig.appVersionCurrent);
913    }
914    // appliacation updated ?
915    if(vconfig.appVersionCurrent > vconfig.appVersionLast){
916        settings->setValue("appVersionLast", vconfig.appVersionCurrent);
917
918        QDateTime timestamp;
919        QString const datefmt = "yyyy-MM-dd";
920        timestamp.setTime_t(vconfig.appVersionCurrent);
921
922        DlgVersion *dlgVersion = new DlgVersion(this);
923        dlgVersion->setMessage(tr("Application updated to version: %1").arg(timestamp.toString(datefmt)));
924        dlgVersion->show();
925
926    }
927
928}
929
930
931void Vtool::on_actionVersion_triggered()
932{
933    QDateTime timestamp;
934    QString const datefmt = "yyyy-MM-dd";
935    timestamp.setTime_t(readLocalAppVersion());
936
937    DlgVersion *dlgVersion = new DlgVersion(this);
938    dlgVersion->setMessage(tr("VoodooTool version: %1").arg(timestamp.toString(datefmt)));
939    dlgVersion->show();
940
941}
942
943void Vtool::on_actionQT_version_triggered()
944{
945    QMessageBox::aboutQt(this);
946}
947
948void Vtool::on_actionCheck_installed_application_triggered()
949{
950    if(!appChecker) appChecker = new DlgAppCheck(this);
951    appChecker->show();
952}
953
954void Vtool::on_actionTest_Remote_triggered()
955{
956    RemoteChecker *rChecker;
957    rChecker = new RemoteChecker(this, vhandle);
958    rChecker->show();
959}
960
961void Vtool::on_actionExit_triggered()
962{
963    qApp->exit();
964}
965
966void Vtool::on_actionShow_eventmap_triggered()
967{
968    EventmapViewer *emViewer = new EventmapViewer(this, vhandle);
969    connect(emViewer, SIGNAL(eventCountChanged()), this, SLOT(updateEventsInUse()));
970    emViewer->show();
971}
972
973void Vtool::on_actionBackup_configuration_triggered()
974{
975    DlgBackup *backup = new DlgBackup(this, vhandle);
976    backup->createBackup();
977}
978
979void Vtool::on_actionRestore_configuration_triggered()
980{
981    DlgBackup *backup = new DlgBackup(this, vhandle);
982    connect(backup, SIGNAL(ready()), this, SLOT(updateEventsInUse()));
983    backup->restoreBackup();
984}
Note: See TracBrowser for help on using the repository browser.