Exemple #1
0
FenPrincipale::FenPrincipale(QWidget *parent) :
    QMainWindow(parent), ui(new Ui::FenPrincipale), m_fenOptions(NULL), m_trayWarningShown(false), m_auth(new Auth(this)), m_handler(new DownloadHandler(this)),
    m_infoExtractor(new InfoExtractor(this)), m_vitesseTransfert(new VitesseTransfert(this, DOWNLOAD_SPEED_UPDATE_INTERVAL, DOWNLOAD_SPEED_AVERAGE_TIME)),
    m_versionCheck(new VersionCheckThread(this, VERSION_HOST, APP_NAME, VERSION, VERSION_NBR)), m_currentDownload(), m_waitTimer(new QTimer(this)),
    m_updateDownloadTimer(new QTimer(this)), m_waitTime(0), m_isDownloading(false)
{
    ui->setupUi(this);
    setWindowTitle(APP_NAME " - v" VERSION);

    //Icône système
    m_menu = new QMenu(this);
    m_retablirAction = new QAction("Rétablir", m_menu);
    m_startAction = new QAction("Télécharger", m_menu);
    m_stopAction = new QAction("Arrêter", m_menu);
    m_quitterAction = new QAction("Quitter", m_menu);
    m_tray = new QSystemTrayIcon(windowIcon(), this);

    m_menu->addAction(m_retablirAction);
    m_menu->addAction(m_startAction);
    m_menu->addAction(m_stopAction);
    m_menu->addAction(m_quitterAction);
    m_retablirAction->setVisible(false);
    m_stopAction->setVisible(false);
    m_tray->setContextMenu(m_menu);
    m_tray->show();

    qApp->setActiveWindow(this);
    loadSettings();

    //UI
    connect(ui->adresse, SIGNAL(returnPressed()), this, SLOT(on_btn_ajouter_clicked()));
    connect(m_waitTimer, SIGNAL(timeout()), this, SLOT(waitTimerTick()));
    connect(m_infoExtractor, SIGNAL(infoAvailable(QString,QString,QString,QString)), this, SLOT(infoAvailable(QString,QString,QString,QString)));
    connect(m_infoExtractor, SIGNAL(infoUnavailable(QString,ExtractionError)), this, SLOT(infoUnavailable(QString,ExtractionError)));
    connect(m_updateDownloadTimer, SIGNAL(timeout()), this, SLOT(updateDownloadTick()));
    connect(m_versionCheck, SIGNAL(update(QString, QString)), this, SLOT(updateAvailable(QString, QString)));
    connect(m_tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayClicked(QSystemTrayIcon::ActivationReason)));
    connect(m_retablirAction, SIGNAL(triggered()), this, SLOT(retablir()));
    connect(m_startAction, SIGNAL(triggered()), this, SLOT(on_btn_go_clicked()));
    connect(m_stopAction, SIGNAL(triggered()), this, SLOT(on_btn_arreter_clicked()));
    connect(m_quitterAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    connect(QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)), this, SLOT(clipboardChange()));

    //Raccourcis
    connect(new QShortcut(QKeySequence("Ctrl+Q"), this), SIGNAL(activated()), qApp, SLOT(quit()));
    connect(new QShortcut(QKeySequence("Ctrl+D"), this), SIGNAL(activated()), ui->btn_details, SLOT(toggle()));
    connect(new QShortcut(QKeySequence("Ctrl+Up"), this), SIGNAL(activated()), this, SLOT(on_btn_monter_clicked()));
    connect(new QShortcut(QKeySequence("Ctrl+Shift+Up"), this), SIGNAL(activated()), this, SLOT(on_btn_monter_clicked()));
    connect(new QShortcut(QKeySequence("Ctrl+Down"), this), SIGNAL(activated()), this, SLOT(on_btn_descendre_clicked()));
    connect(new QShortcut(QKeySequence("Ctrl+Shift+Down"), this), SIGNAL(activated()), this, SLOT(on_btn_descendre_clicked()));
    connect(new QShortcut(QKeySequence("Del"), this), SIGNAL(activated()), this, SLOT(on_btn_supprimer_clicked()));

    //Téléchargement
    connect(m_auth, SIGNAL(authed(AuthInfo)), this, SLOT(authSuccess(AuthInfo)));
    connect(m_auth, SIGNAL(authError(AuthError)), this, SLOT(authFail(AuthError)));
    connect(m_handler, SIGNAL(error(DownloadError)), this, SLOT(error(DownloadError)));
    connect(m_handler, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateDownload(qint64, qint64)));
    connect(m_handler, SIGNAL(finished()), this, SLOT(downloadComplete()));
    connect(m_handler, SIGNAL(waitTime(int, QString)), this, SLOT(waitTimerStart(int, QString)));

    console("Authentification...");
    m_auth->login(m_login, m_password);
    m_updateDownloadTimer->setInterval(DOWNLOAD_SPEED_UPDATE_INTERVAL);
    m_versionCheck->start();
    m_waitTimer->setInterval(1000);
    clipboardChange();  //Initialise la zone d'adresse avec les adresses déjà présentes en mémoire.
    setDetailsVisible(ui->btn_details->isChecked());
    ui->btn_arreter->hide();
    ui->liste->setCurrentRow(0);

    sLog->out(APP_NAME " startup.");
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    nbonglet=0;
    mesonglets = new Onglet();
    ui->setupUi(this);
    QVBoxLayout* l = new QVBoxLayout();
    ui->centralWidget->setLayout(l);;
    l->addWidget(mesonglets);
    l->addWidget(ui->frame);
    mesonglets->setMaximumHeight(24);
    mesonglets->setTabsClosable(true);

    nouvelOnglet();

    QObject::connect(ui->num0,SIGNAL(clicked()),this,SLOT(num0Pressed()));
    QObject::connect(ui->num1,SIGNAL(clicked()),this,SLOT(num1Pressed()));
    QObject::connect(ui->num2,SIGNAL(clicked()),this,SLOT(num2Pressed()));
    QObject::connect(ui->num3,SIGNAL(clicked()),this,SLOT(num3Pressed()));
    QObject::connect(ui->num4,SIGNAL(clicked()),this,SLOT(num4Pressed()));
    QObject::connect(ui->num5,SIGNAL(clicked()),this,SLOT(num5Pressed()));
    QObject::connect(ui->num6,SIGNAL(clicked()),this,SLOT(num6Pressed()));
    QObject::connect(ui->num7,SIGNAL(clicked()),this,SLOT(num7Pressed()));
    QObject::connect(ui->num8,SIGNAL(clicked()),this,SLOT(num8Pressed()));
    QObject::connect(ui->num9,SIGNAL(clicked()),this,SLOT(num9Pressed()));
    QObject::connect(ui->sinButton,SIGNAL(clicked()),this,SLOT(SINPressed()));
    QObject::connect(ui->sinhButton,SIGNAL(clicked()),this,SLOT(SINHPressed()));
    QObject::connect(ui->cosButton,SIGNAL(clicked()),this,SLOT(COSPressed()));
    QObject::connect(ui->coshButton,SIGNAL(clicked()),this,SLOT(COSHPressed()));
    QObject::connect(ui->tanButton,SIGNAL(clicked()),this,SLOT(TANPressed()));
    QObject::connect(ui->tanhButton,SIGNAL(clicked()),this,SLOT(TANHPressed()));
    QObject::connect(ui->lnButton,SIGNAL(clicked()),this,SLOT(LNPressed()));
    QObject::connect(ui->logButton,SIGNAL(clicked()),this,SLOT(LOGPressed()));
    QObject::connect(ui->cubeButton,SIGNAL(clicked()),this,SLOT(CUBEPressed()));
    QObject::connect(ui->sqrButton,SIGNAL(clicked()),this,SLOT(SQRPressed()));
    QObject::connect(ui->sqrtButton,SIGNAL(clicked()),this,SLOT(SQRTPressed()));
    QObject::connect(ui->invButton,SIGNAL(clicked()),this,SLOT(INVPressed()));
    QObject::connect(ui->factButton,SIGNAL(clicked()),this,SLOT(FACTPressed()));
    QObject::connect(ui->addButton,SIGNAL(clicked()),this,SLOT(ADDPressed()));
    QObject::connect(ui->minusButton,SIGNAL(clicked()),this,SLOT(MINUSPressed()));
    QObject::connect(ui->multiplyButton,SIGNAL(clicked()),this,SLOT(MULTPressed()));
    QObject::connect(ui->divButton,SIGNAL(clicked()),this,SLOT(DIVPressed()));
    QObject::connect(ui->powButton,SIGNAL(clicked()),this,SLOT(POWPressed()));
    QObject::connect(ui->modButton,SIGNAL(clicked()),this,SLOT(MODPressed()));
    QObject::connect(ui->signButton,SIGNAL(clicked()),this,SLOT(SIGNPressed()));
    QObject::connect(ui->spaceButton,SIGNAL(clicked()),this,SLOT(spacePressed()));
    QObject::connect(ui->ratioButton,SIGNAL(clicked()),this,SLOT(ratioClicked()));
    QObject::connect(ui->realButton,SIGNAL(clicked()),this,SLOT(realClicked()));
    QObject::connect(ui->integerButton,SIGNAL(clicked()),this,SLOT(integerClicked()));
    QObject::connect(ui->degreButton,SIGNAL(clicked()),this,SLOT(degreClicked()));
    QObject::connect(ui->radianButton,SIGNAL(clicked()),this,SLOT(radianClicked()));
    QObject::connect(ui->trueComplexButton,SIGNAL(clicked()),this,SLOT(trueComplexClicked()));
    QObject::connect(ui->falseComplexButton,SIGNAL(clicked()),this,SLOT(falseComplexClicked()));
    QObject::connect(mesonglets,SIGNAL(tabCloseRequested(int)),this,SLOT(fermerOnglet(int)));
    QObject::connect(ui->actionNouvel_Onglet,SIGNAL(triggered()),this,SLOT(nouvelOnglet()));
    QObject::connect(ui->pointButton,SIGNAL(clicked()),this,SLOT(pointPressed()));
    QObject::connect(ui->slashButton,SIGNAL(clicked()),this,SLOT(slashPressed()));
    QObject::connect(ui->dollarButton,SIGNAL(clicked()),this,SLOT(dollarPressed()));
    QObject::connect(ui->quoteButton,SIGNAL(clicked()),this,SLOT(quotePressed()));
    QObject::connect(mesonglets,SIGNAL(currentChanged(int)),this,SLOT(changerOnglet(int)));
    QObject::connect(ui->evalButton,SIGNAL(clicked()),this,SLOT(evalPressed()));
    QObject::connect(ui->action_Quit,SIGNAL(triggered()),this,SLOT(Quitter()));
    QObject::connect(ui->actionAnnuler,SIGNAL(triggered()),this,SLOT(annuler()));
    QObject::connect(ui->actionR_tablir,SIGNAL(triggered()),this,SLOT(retablir()));

}