X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fwin_main.cpp;h=2495b8b49e5cd80267144dead2196ee07bbbbac8;hb=7fe6779177716755fd4ff282dc2f58024882bb0b;hp=02c7874c720e1c95933c99dba13fb8939a6adf92;hpb=f80533f99acd56da3ff297f2297a7343d6c9553f;p=x264-launcher%2Fx264-launcher.git diff --git a/src/win_main.cpp b/src/win_main.cpp index 02c7874..2495b8b 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Simple x264 Launcher -// Copyright (C) 2004-2014 LoRd_MuldeR +// Copyright (C) 2004-2020 LoRd_MuldeR // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,8 +20,9 @@ /////////////////////////////////////////////////////////////////////////////// #include "win_main.h" -#include "uic_win_main.h" +#include "UIC_win_main.h" +//Internal #include "global.h" #include "cli.h" #include "ipc.h" @@ -32,17 +33,28 @@ #include "model_preferences.h" #include "model_recently.h" #include "thread_avisynth.h" +#include "thread_binaries.h" #include "thread_vapoursynth.h" #include "thread_encode.h" -#include "taskbar7.h" +#include "thread_ipc_recv.h" #include "input_filter.h" #include "win_addJob.h" #include "win_about.h" #include "win_preferences.h" #include "win_updater.h" -#include "binaries.h" #include "resource.h" +//MUtils +#include +#include +#include +#include +#include +#include +#include +#include + +//Qt #include #include #include @@ -57,20 +69,29 @@ #include #include #include - +#include +#include +#include #include -const char *home_url = "http://muldersoft.com/"; -const char *update_url = "https://github.com/lordmulder/Simple-x264-Launcher/releases/latest"; -const char *tpl_last = ""; +//Constants +static const char *tpl_last = ""; +static const char *home_url = "http://muldersoft.com/"; +static const char *update_url = "https://github.com/lordmulder/Simple-x264-Launcher/releases/latest"; +static const char *avs_dl_url = "http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/"; +static const char *python_url = "https://www.python.org/downloads/"; +static const char *vsynth_url = "http://www.vapoursynth.com/"; +static const int vsynth_rev = 24; +//Macros #define SET_FONT_BOLD(WIDGET,BOLD) do { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } while(0) #define SET_TEXT_COLOR(WIDGET,COLOR) do { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); } while(0) -#define LINK(URL) "" URL "" -#define INIT_ERROR_EXIT() do { m_status = STATUS_EXITTING; close(); qApp->exit(-1); return; } while(0) -#define ENSURE_APP_IS_IDLE() do { if(m_status != STATUS_IDLE) { x264_beep(x264_beep_warning); qWarning("Cannot perfrom this action at this time!"); return; } } while(0) -#define NEXT(X) ((*reinterpret_cast(&(X)))++) +#define LINK(URL) (QString("%1").arg((URL))) +#define INIT_ERROR_EXIT() do { close(); qApp->exit(-1); return; } while(0) #define SETUP_WEBLINK(OBJ, URL) do { (OBJ)->setData(QVariant(QUrl(URL))); connect((OBJ), SIGNAL(triggered()), this, SLOT(showWebLink())); } while(0) +#define APP_IS_READY (m_initialized && (!m_fileTimer->isActive()) && (QApplication::activeModalWidget() == NULL)) +#define ENSURE_APP_IS_READY() do { if(!APP_IS_READY) { MUtils::Sound::beep(MUtils::Sound::BEEP_WRN); qWarning("Cannot perfrom this action at this time!"); return; } } while(0) +#define X264_STRCMP(X,Y) ((X).compare((Y), Qt::CaseInsensitive) == 0) /////////////////////////////////////////////////////////////////////////////// // Constructor & Destructor @@ -79,16 +100,17 @@ const char *tpl_last = ""; /* * Constructor */ -MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc) +MainWindow::MainWindow(const MUtils::CPUFetaures::cpu_info_t &cpuFeatures, MUtils::IPCChannel *const ipcChannel) : - m_ipc(ipc), + m_ipcChannel(ipcChannel), m_sysinfo(NULL), m_options(NULL), m_jobList(NULL), m_pendingFiles(new QStringList()), m_preferences(NULL), m_recentlyUsed(NULL), - m_status(STATUS_PRE_INIT), + m_postOperation(POST_OP_DONOTHING), + m_initialized(false), ui(new Ui::MainWindow()) { //Init the dialog, from the .ui file @@ -101,32 +123,35 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc) qRegisterMetaType("JobStatus"); //Create and initialize the sysinfo object - m_sysinfo = new SysinfoModel(); + m_sysinfo.reset(new SysinfoModel()); m_sysinfo->setAppPath(QApplication::applicationDirPath()); - m_sysinfo->setMMXSupport(cpuFeatures->mmx && cpuFeatures->mmx2); - m_sysinfo->setSSESupport(cpuFeatures->sse && cpuFeatures->mmx2); //SSE implies MMX2 - m_sysinfo->setX64Support(cpuFeatures->x64 && cpuFeatures->sse2); //X64 implies SSE2 + m_sysinfo->setCPUFeatures(SysinfoModel::CPUFeatures_MMX, cpuFeatures.features & MUtils::CPUFetaures::FLAG_MMX); + m_sysinfo->setCPUFeatures(SysinfoModel::CPUFeatures_SSE, cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE); + m_sysinfo->setCPUFeatures(SysinfoModel::CPUFeatures_X64, cpuFeatures.x64 && (cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE2)); //X64 implies SSE2 //Load preferences - m_preferences = new PreferencesModel(); - PreferencesModel::loadPreferences(m_preferences); + m_preferences.reset(new PreferencesModel()); + PreferencesModel::loadPreferences(m_preferences.data()); //Load recently used - m_recentlyUsed = new RecentlyUsed(); - RecentlyUsed::loadRecentlyUsed(m_recentlyUsed); + m_recentlyUsed.reset(new RecentlyUsed()); + RecentlyUsed::loadRecentlyUsed(m_recentlyUsed.data()); //Create options object - m_options = new OptionsModel(m_sysinfo); - OptionsModel::loadTemplate(m_options, QString::fromLatin1(tpl_last)); + m_options.reset(new OptionsModel(m_sysinfo.data())); + OptionsModel::loadTemplate(m_options.data(), QString::fromLatin1(tpl_last)); + + //DPI scaling + MUtils::GUI::scale_widget(this); //Freeze minimum size setMinimumSize(size()); ui->splitter->setSizes(QList() << 16 << 196); //Update title - ui->labelBuildDate->setText(tr("Built on %1 at %2").arg(x264_version_date().toString(Qt::ISODate), QString::fromLatin1(x264_version_time()))); + ui->labelBuildDate->setText(tr("Built on %1 at %2").arg(MUtils::Version::app_build_date().toString(Qt::ISODate), MUtils::Version::app_build_time().toString(Qt::ISODate))); - if(X264_DEBUG) + if(MUTILS_DEBUG) { setWindowTitle(QString("%1 | !!! DEBUG VERSION !!!").arg(windowTitle())); setStyleSheet("QMenuBar, QMainWindow { background-color: yellow }"); @@ -137,37 +162,48 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc) } //Create model - m_jobList = new JobListModel(m_preferences); - connect(m_jobList, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(jobChangedData(QModelIndex, QModelIndex))); - ui->jobsView->setModel(m_jobList); + m_jobList.reset(new JobListModel(m_preferences.data())); + connect(m_jobList.data(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(jobChangedData(QModelIndex, QModelIndex))); + ui->jobsView->setModel(m_jobList.data()); //Setup view ui->jobsView->horizontalHeader()->setSectionHidden(3, true); ui->jobsView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - ui->jobsView->horizontalHeader()->setResizeMode(1, QHeaderView::Fixed); - ui->jobsView->horizontalHeader()->setResizeMode(2, QHeaderView::Fixed); - ui->jobsView->horizontalHeader()->resizeSection(1, 150); - ui->jobsView->horizontalHeader()->resizeSection(2, 90); + ui->jobsView->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + ui->jobsView->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents); + ui->jobsView->horizontalHeader()->setMinimumSectionSize(96); ui->jobsView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); connect(ui->jobsView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(jobSelected(QModelIndex, QModelIndex))); //Setup key listener - m_inputFilter_jobList = new InputEventFilter(ui->jobsView); + m_inputFilter_jobList.reset(new InputEventFilter(ui->jobsView)); m_inputFilter_jobList->addKeyFilter(Qt::ControlModifier | Qt::Key_Up, 1); m_inputFilter_jobList->addKeyFilter(Qt::ControlModifier | Qt::Key_Down, 2); - connect(m_inputFilter_jobList, SIGNAL(keyPressed(int)), this, SLOT(jobListKeyPressed(int))); + connect(m_inputFilter_jobList.data(), SIGNAL(keyPressed(int)), this, SLOT(jobListKeyPressed(int))); //Setup mouse listener - m_inputFilter_version = new InputEventFilter(ui->labelBuildDate); + m_inputFilter_version.reset(new InputEventFilter(ui->labelBuildDate)); m_inputFilter_version->addMouseFilter(Qt::LeftButton, 0); m_inputFilter_version->addMouseFilter(Qt::RightButton, 0); - connect(m_inputFilter_version, SIGNAL(mouseClicked(int)), this, SLOT(versionLabelMouseClicked(int))); + connect(m_inputFilter_version.data(), SIGNAL(mouseClicked(int)), this, SLOT(versionLabelMouseClicked(int))); //Create context menu QAction *actionClipboard = new QAction(QIcon(":/buttons/page_paste.png"), tr("Copy to Clipboard"), ui->logView); + QAction *actionSaveToLog = new QAction(QIcon(":/buttons/disk.png"), tr("Save to File..."), ui->logView); + QAction *actionSeparator = new QAction(ui->logView); + QAction *actionWordwraps = new QAction(QIcon(":/buttons/text_wrapping.png"), tr("Enable Line-Wrapping"), ui->logView); + actionSeparator->setSeparator(true); + actionWordwraps->setCheckable(true); actionClipboard->setEnabled(false); + actionSaveToLog->setEnabled(false); + actionWordwraps->setEnabled(false); ui->logView->addAction(actionClipboard); + ui->logView->addAction(actionSaveToLog); + ui->logView->addAction(actionSeparator); + ui->logView->addAction(actionWordwraps); connect(actionClipboard, SIGNAL(triggered(bool)), this, SLOT(copyLogToClipboard(bool))); + connect(actionSaveToLog, SIGNAL(triggered(bool)), this, SLOT(saveLogToLocalFile(bool))); + connect(actionWordwraps, SIGNAL(triggered(bool)), this, SLOT(toggleLineWrapping(bool))); ui->jobsView->addActions(ui->menuJob->actions()); //Enable buttons @@ -182,45 +218,96 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc) connect(ui->actionJob_MoveDown, SIGNAL(triggered()), this, SLOT(moveButtonPressed() )); //Enable menu - connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openActionTriggered())); - connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout())); - connect(ui->actionPreferences, SIGNAL(triggered()), this, SLOT(showPreferences())); - connect(ui->actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(checkUpdates())); + connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openActionTriggered())); + connect(ui->actionCleanup_Finished, SIGNAL(triggered()), this, SLOT(cleanupActionTriggered())); + connect(ui->actionCleanup_Enqueued, SIGNAL(triggered()), this, SLOT(cleanupActionTriggered())); + connect(ui->actionPostOp_DoNothing, SIGNAL(triggered()), this, SLOT(postOpActionTriggered())); + connect(ui->actionPostOp_PowerDown, SIGNAL(triggered()), this, SLOT(postOpActionTriggered())); + connect(ui->actionPostOp_Hibernate, SIGNAL(triggered()), this, SLOT(postOpActionTriggered())); + connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout())); + connect(ui->actionPreferences, SIGNAL(triggered()), this, SLOT(showPreferences())); + connect(ui->actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(checkUpdates())); + ui->actionCleanup_Finished->setData(QVariant(bool(0))); + ui->actionCleanup_Enqueued->setData(QVariant(bool(1))); + ui->actionPostOp_DoNothing->setData(QVariant(POST_OP_DONOTHING)); + ui->actionPostOp_PowerDown->setData(QVariant(POST_OP_POWERDOWN)); + ui->actionPostOp_Hibernate->setData(QVariant(POST_OP_HIBERNATE)); + ui->actionPostOp_Hibernate->setEnabled(MUtils::OS::is_hibernation_supported()); //Setup web-links SETUP_WEBLINK(ui->actionWebMulder, home_url); SETUP_WEBLINK(ui->actionWebX264, "http://www.videolan.org/developers/x264.html"); SETUP_WEBLINK(ui->actionWebX265, "http://www.videolan.org/developers/x265.html"); - SETUP_WEBLINK(ui->actionWebKomisar, "http://komisar.gin.by/"); - SETUP_WEBLINK(ui->actionWebVideoLAN, "http://download.videolan.org/pub/x264/binaries/"); - SETUP_WEBLINK(ui->actionWebJEEB, "http://x264.fushizen.eu/"); - SETUP_WEBLINK(ui->actionWebFreeCodecs, "http://www.free-codecs.com/x264_video_codec_download.htm"); - SETUP_WEBLINK(ui->actionWebX265BinRU, "http://goo.gl/xRS6AW"); - SETUP_WEBLINK(ui->actionWebX265BinEU, "http://builds.x265.eu/"); - SETUP_WEBLINK(ui->actionWebX265BinORG, "http://chromashift.org/x265_builds/"); - SETUP_WEBLINK(ui->actionWebX265BinFF, "http://ffmpeg.zeranoe.com/builds/"); - SETUP_WEBLINK(ui->actionWebAvisynth32, "http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/"); - SETUP_WEBLINK(ui->actionWebAvisynth64, "http://code.google.com/p/avisynth64/downloads/list"); + SETUP_WEBLINK(ui->actionWebX264LigH, "http://www.mediafire.com/?bxvu1vvld31k1"); + SETUP_WEBLINK(ui->actionWebX264VideoLAN, "http://artifacts.videolan.org/x264/"); + SETUP_WEBLINK(ui->actionWebX264Komisar, "http://komisar.gin.by/"); + SETUP_WEBLINK(ui->actionWebX265LigH, "http://www.mediafire.com/?6lfp2jlygogwa"); + SETUP_WEBLINK(ui->actionWebX264FreeCodecs, "http://www.free-codecs.com/x264_video_codec_download.htm"); + SETUP_WEBLINK(ui->actionWebX265Fllear, "http://x265.ru/en/builds/"); + SETUP_WEBLINK(ui->actionWebX265Snowfag, "http://builds.x265.eu/"); + SETUP_WEBLINK(ui->actionWebX265FreeCodecs, "http://www.free-codecs.com/x265_hevc_encoder_download.htm"); + SETUP_WEBLINK(ui->actionWebAvisynth32, "https://sourceforge.net/projects/avisynth2/files/AviSynth%202.6/"); + SETUP_WEBLINK(ui->actionWebAvisynth64, "http://forum.doom9.org/showthread.php?t=152800"); SETUP_WEBLINK(ui->actionWebAvisynthPlus, "http://www.avs-plus.net/"); SETUP_WEBLINK(ui->actionWebVapourSynth, "http://www.vapoursynth.com/"); SETUP_WEBLINK(ui->actionWebVapourSynthDocs, "http://www.vapoursynth.com/doc/"); - SETUP_WEBLINK(ui->actionWebWiki, "http://mewiki.project357.com/wiki/X264_Settings"); + SETUP_WEBLINK(ui->actionOnlineDocX264, "http://en.wikibooks.org/wiki/MeGUI/x264_Settings"); //http://mewiki.project357.com/wiki/X264_Settings + SETUP_WEBLINK(ui->actionOnlineDocX265, "http://x265.readthedocs.org/en/default/"); SETUP_WEBLINK(ui->actionWebBluRay, "http://www.x264bluray.com/"); SETUP_WEBLINK(ui->actionWebAvsWiki, "http://avisynth.nl/index.php/Main_Page#Usage"); SETUP_WEBLINK(ui->actionWebSupport, "http://forum.doom9.org/showthread.php?t=144140"); SETUP_WEBLINK(ui->actionWebSecret, "http://www.youtube.com/watch_popup?v=AXIeHY-OYNI"); //Create floating label - m_label = new QLabel(ui->jobsView->viewport()); - m_label->setText(tr("No job created yet. Please click the 'Add New Job' button!")); - m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - SET_TEXT_COLOR(m_label, Qt::darkGray); - SET_FONT_BOLD(m_label, true); - m_label->setVisible(true); - m_label->setContextMenuPolicy(Qt::ActionsContextMenu); - m_label->addActions(ui->jobsView->actions()); + m_label[0].reset(new QLabel(ui->jobsView->viewport())); + m_label[1].reset(new QLabel(ui->logView->viewport())); + if(!m_label[0].isNull()) + { + m_label[0]->setText(tr("No job created yet. Please click the 'Add New Job' button!")); + m_label[0]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + SET_TEXT_COLOR(m_label[0], Qt::darkGray); + SET_FONT_BOLD(m_label[0], true); + m_label[0]->setVisible(true); + m_label[0]->setContextMenuPolicy(Qt::ActionsContextMenu); + m_label[0]->addActions(ui->jobsView->actions()); + } + if(!m_label[1].isNull()) + { + m_animation.reset(new QMovie(":/images/spinner.gif")); + m_label[1]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + if(!m_animation.isNull()) + { + m_label[1]->setMovie(m_animation.data()); + m_animation->start(); + } + } connect(ui->splitter, SIGNAL(splitterMoved(int, int)), this, SLOT(updateLabelPos())); updateLabelPos(); + + //Init system tray icon + m_sysTray.reset(new QSystemTrayIcon(this)); + m_sysTray->setToolTip(this->windowTitle()); + m_sysTray->setIcon(this->windowIcon()); + connect(m_sysTray.data(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayActived())); + + //Init taskbar progress + m_taskbar.reset(new MUtils::Taskbar7(this)); + + //Create corner widget + QLabel *checkUp = new QLabel(ui->menubar); + checkUp->setText(QString(" %1   ").arg(tr("Check for Updates"))); + checkUp->setFixedHeight(ui->menubar->height()); + checkUp->setCursor(QCursor(Qt::PointingHandCursor)); + m_inputFilter_checkUp.reset(new InputEventFilter(checkUp)); + m_inputFilter_checkUp->addMouseFilter(Qt::LeftButton, 0); + m_inputFilter_checkUp->addMouseFilter(Qt::RightButton, 0); + connect(m_inputFilter_checkUp.data(), SIGNAL(mouseClicked(int)), this, SLOT(checkUpdates())); + checkUp->hide(); + ui->menubar->setCornerWidget(checkUp); + + //Create timer + m_fileTimer.reset(new QTimer(this)); + connect(m_fileTimer.data(), SIGNAL(timeout()), this, SLOT(handlePendingFiles())); } /* @@ -228,34 +315,18 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc) */ MainWindow::~MainWindow(void) { - m_status = STATUS_EXITTING; - OptionsModel::saveTemplate(m_options, QString::fromLatin1(tpl_last)); + OptionsModel::saveTemplate(m_options.data(), QString::fromLatin1(tpl_last)); - X264_DELETE(m_jobList); - X264_DELETE(m_options); - X264_DELETE(m_pendingFiles); - X264_DELETE(m_label); - X264_DELETE(m_inputFilter_jobList); - X264_DELETE(m_inputFilter_version); - - while(!m_toolsList.isEmpty()) + if(!m_ipcThread.isNull()) { - QFile *temp = m_toolsList.takeFirst(); - X264_DELETE(temp); - } - - if(m_ipc->isListening()) - { - m_ipc->stopListening(); + m_ipcThread->stop(); + if(!m_ipcThread->wait(5000)) + { + m_ipcThread->terminate(); + m_ipcThread->wait(); + } } - X264_DELETE(m_preferences); - X264_DELETE(m_recentlyUsed); - X264_DELETE(m_sysinfo); - - VapourSynthCheckThread::unload(); - AvisynthCheckThread::unload(); - delete ui; } @@ -268,19 +339,16 @@ MainWindow::~MainWindow(void) */ void MainWindow::addButtonPressed() { - ENSURE_APP_IS_IDLE(); - m_status = STATUS_BLOCKED; + ENSURE_APP_IS_READY(); qDebug("MainWindow::addButtonPressed"); bool runImmediately = (countRunningJobs() < (m_preferences->getAutoRunNextJob() ? m_preferences->getMaxRunningJobCount() : 1)); QString sourceFileName, outputFileName; - if(createJob(sourceFileName, outputFileName, m_options, runImmediately)) + if(createJob(sourceFileName, outputFileName, m_options.data(), runImmediately)) { - appendJob(sourceFileName, outputFileName, m_options, runImmediately); + appendJob(sourceFileName, outputFileName, m_options.data(), runImmediately); } - - m_status = STATUS_IDLE; } /* @@ -288,8 +356,8 @@ void MainWindow::addButtonPressed() */ void MainWindow::openActionTriggered() { - ENSURE_APP_IS_IDLE(); - m_status = STATUS_BLOCKED; + ENSURE_APP_IS_READY(); + qWarning("openActionTriggered()"); QStringList fileList = QFileDialog::getOpenFileNames(this, tr("Open Source File(s)"), m_recentlyUsed->sourceDirectory(), AddJobDialog::getInputFilterLst(), NULL, QFileDialog::DontUseNativeDialog); if(!fileList.empty()) @@ -303,14 +371,82 @@ void MainWindow::openActionTriggered() { bool runImmediately = (countRunningJobs() < (m_preferences->getAutoRunNextJob() ? m_preferences->getMaxRunningJobCount() : 1)); QString sourceFileName(fileList.first()), outputFileName; - if(createJob(sourceFileName, outputFileName, m_options, runImmediately)) + if(createJob(sourceFileName, outputFileName, m_options.data(), runImmediately)) { - appendJob(sourceFileName, outputFileName, m_options, runImmediately); + appendJob(sourceFileName, outputFileName, m_options.data(), runImmediately); } } } +} - m_status = STATUS_IDLE; +/* +* The "clean-up" action was invoked +*/ +void MainWindow::cleanupActionTriggered(void) +{ + ENSURE_APP_IS_READY(); + + QAction *const sender = dynamic_cast(QObject::sender()); + if (sender) + { + const QVariant data = sender->data(); + if (data.isValid() && (data.type() == QVariant::Bool)) + { + const bool mode = data.toBool(); + const int rows = m_jobList->rowCount(QModelIndex()); + QList jobIndices; + for (int i = 0; i < rows; i++) + { + const JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex())); + if (mode && (status == JobStatus_Enqueued)) + { + jobIndices.append(i); + } + else if ((!mode) && ((status == JobStatus_Completed) || (status == JobStatus_Aborted) || (status == JobStatus_Failed))) + { + jobIndices.append(i); + } + } + if (!jobIndices.isEmpty()) + { + QListIterator iter(jobIndices); + iter.toBack(); + while(iter.hasPrevious()) + { + m_jobList->deleteJob(m_jobList->index(iter.previous(), 0, QModelIndex())); + } + } + else + { + MUtils::Sound::beep(MUtils::Sound::BEEP_WRN); + } + } + } +} + +/* +* The "clean-up" action was invoked +*/ +void MainWindow::postOpActionTriggered(void) +{ + ENSURE_APP_IS_READY(); + + QAction *const sender = dynamic_cast(QObject::sender()); + if (sender) + { + const QVariant data = sender->data(); + if (data.isValid() && (data.type() == QVariant::Int)) + { + const postOp_t mode = (postOp_t)data.toInt(); + if ((mode >= POST_OP_DONOTHING) && (mode <= POST_OP_HIBERNATE)) + { + m_postOperation = mode; + ui->actionPostOp_PowerDown->setChecked(mode == POST_OP_POWERDOWN); + ui->actionPostOp_Hibernate->setChecked(mode == POST_OP_HIBERNATE); + ui->actionPostOp_DoNothing->setChecked(mode == POST_OP_DONOTHING); + } + } + } } /* @@ -318,7 +454,7 @@ void MainWindow::openActionTriggered() */ void MainWindow::startButtonPressed(void) { - ENSURE_APP_IS_IDLE(); + ENSURE_APP_IS_READY(); m_jobList->startJob(ui->jobsView->currentIndex()); } @@ -327,15 +463,12 @@ void MainWindow::startButtonPressed(void) */ void MainWindow::abortButtonPressed(void) { - ENSURE_APP_IS_IDLE(); - m_status = STATUS_BLOCKED; + ENSURE_APP_IS_READY(); if(QMessageBox::question(this, tr("Abort Job?"), tr("Do you really want to abort the selected job now?"), tr("Back"), tr("Abort Job")) == 1) { m_jobList->abortJob(ui->jobsView->currentIndex()); } - - m_status = STATUS_IDLE; } /* @@ -343,9 +476,10 @@ void MainWindow::abortButtonPressed(void) */ void MainWindow::deleteButtonPressed(void) { - ENSURE_APP_IS_IDLE(); + ENSURE_APP_IS_READY(); + m_jobList->deleteJob(ui->jobsView->currentIndex()); - m_label->setVisible(m_jobList->rowCount(QModelIndex()) == 0); + m_label[0]->setVisible(m_jobList->rowCount(QModelIndex()) == 0); } /* @@ -353,8 +487,7 @@ void MainWindow::deleteButtonPressed(void) */ void MainWindow::browseButtonPressed(void) { - ENSURE_APP_IS_IDLE(); - m_status = STATUS_BLOCKED; + ENSURE_APP_IS_READY(); QString outputFile = m_jobList->getJobOutputFile(ui->jobsView->currentIndex()); if((!outputFile.isEmpty()) && QFileInfo(outputFile).exists() && QFileInfo(outputFile).isFile()) @@ -365,8 +498,6 @@ void MainWindow::browseButtonPressed(void) { QMessageBox::warning(this, tr("Not Found"), tr("Sorry, the output file could not be found!")); } - - m_status = STATUS_IDLE; } /* @@ -374,14 +505,14 @@ void MainWindow::browseButtonPressed(void) */ void MainWindow::moveButtonPressed(void) { - ENSURE_APP_IS_IDLE(); + ENSURE_APP_IS_READY(); if(sender() == ui->actionJob_MoveUp) { qDebug("Move job %d (direction: UP)", ui->jobsView->currentIndex().row()); if(!m_jobList->moveJob(ui->jobsView->currentIndex(), JobListModel::MOVE_UP)) { - x264_beep(x264_beep_error); + MUtils::Sound::beep(MUtils::Sound::BEEP_ERR); } ui->jobsView->scrollTo(ui->jobsView->currentIndex(), QAbstractItemView::PositionAtCenter); } @@ -390,7 +521,7 @@ void MainWindow::moveButtonPressed(void) qDebug("Move job %d (direction: DOWN)", ui->jobsView->currentIndex().row()); if(!m_jobList->moveJob(ui->jobsView->currentIndex(), JobListModel::MOVE_DOWN)) { - x264_beep(x264_beep_error); + MUtils::Sound::beep(MUtils::Sound::BEEP_ERR); } ui->jobsView->scrollTo(ui->jobsView->currentIndex(), QAbstractItemView::PositionAtCenter); } @@ -405,7 +536,12 @@ void MainWindow::moveButtonPressed(void) */ void MainWindow::pauseButtonPressed(bool checked) { - ENSURE_APP_IS_IDLE(); + if(!APP_IS_READY) + { + MUtils::Sound::beep(MUtils::Sound::BEEP_WRN); + qWarning("Cannot perfrom this action at this time!"); + ui->buttonPauseJob->setChecked(!checked); + } if(checked) { @@ -422,7 +558,7 @@ void MainWindow::pauseButtonPressed(bool checked) */ void MainWindow::restartButtonPressed(void) { - ENSURE_APP_IS_IDLE(); + ENSURE_APP_IS_READY(); const QModelIndex index = ui->jobsView->currentIndex(); const OptionsModel *options = m_jobList->getJobOptions(index); @@ -437,7 +573,7 @@ void MainWindow::restartButtonPressed(void) { appendJob(sourceFileName, outputFileName, tempOptions, runImmediately); } - X264_DELETE(tempOptions); + MUTILS_DELETE(tempOptions); } } @@ -457,7 +593,10 @@ void MainWindow::jobSelected(const QModelIndex & current, const QModelIndex & pr { ui->logView->setModel(m_jobList->getLogFile(current)); connect(ui->logView->model(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(jobLogExtended(QModelIndex, int, int))); - ui->logView->actions().first()->setEnabled(true); + foreach(QAction *action, ui->logView->actions()) + { + action->setEnabled(true); + } QTimer::singleShot(0, ui->logView, SLOT(scrollToBottom())); ui->progressBar->setValue(m_jobList->getJobProgress(current)); @@ -468,7 +607,10 @@ void MainWindow::jobSelected(const QModelIndex & current, const QModelIndex & pr else { ui->logView->setModel(NULL); - ui->logView->actions().first()->setEnabled(false); + foreach(QAction *action, ui->logView->actions()) + { + action->setEnabled(false); + } ui->progressBar->setValue(0); ui->editDetails->clear(); updateButtons(JobStatus_Undefined); @@ -499,7 +641,6 @@ void MainWindow::jobChangedData(const QModelIndex &topLeft, const QModelIndex & if((status == JobStatus_Completed) || (status == JobStatus_Failed)) { if(m_preferences->getAutoRunNextJob()) QTimer::singleShot(0, this, SLOT(launchNextJob())); - if(m_preferences->getShutdownComputer()) QTimer::singleShot(0, this, SLOT(shutdownComputer())); if(m_preferences->getSaveLogFiles()) saveLogFile(m_jobList->index(i, 1, QModelIndex())); } } @@ -511,7 +652,10 @@ void MainWindow::jobChangedData(const QModelIndex &topLeft, const QModelIndex & if(i == selected) { ui->progressBar->setValue(m_jobList->getJobProgress(m_jobList->index(i, 0, QModelIndex()))); - WinSevenTaskbar::setTaskbarProgress(this, ui->progressBar->value(), ui->progressBar->maximum()); + if(!m_taskbar.isNull()) + { + m_taskbar->setTaskbarProgress(ui->progressBar->value(), ui->progressBar->maximum()); + } break; } } @@ -542,16 +686,13 @@ void MainWindow::jobLogExtended(const QModelIndex & parent, int start, int end) */ void MainWindow::showAbout(void) { - ENSURE_APP_IS_IDLE(); - m_status = STATUS_BLOCKED; + ENSURE_APP_IS_READY(); if(AboutDialog *aboutDialog = new AboutDialog(this)) { aboutDialog->exec(); - X264_DELETE(aboutDialog); + MUTILS_DELETE(aboutDialog); } - - m_status = STATUS_IDLE; } /* @@ -559,7 +700,7 @@ void MainWindow::showAbout(void) */ void MainWindow::showWebLink(void) { - ENSURE_APP_IS_IDLE(); + ENSURE_APP_IS_READY(); if(QObject *obj = QObject::sender()) { @@ -578,14 +719,12 @@ void MainWindow::showWebLink(void) */ void MainWindow::showPreferences(void) { - ENSURE_APP_IS_IDLE(); - m_status = STATUS_BLOCKED; + ENSURE_APP_IS_READY(); - PreferencesDialog *preferences = new PreferencesDialog(this, m_preferences, m_sysinfo); + PreferencesDialog *preferences = new PreferencesDialog(this, m_preferences.data(), m_sysinfo.data()); preferences->exec(); - X264_DELETE(preferences); - m_status = STATUS_IDLE; + MUTILS_DELETE(preferences); } /* @@ -593,9 +732,7 @@ void MainWindow::showPreferences(void) */ void MainWindow::launchNextJob(void) { - qDebug("launchNextJob(void)"); - - const int rows = m_jobList->rowCount(QModelIndex()); + qDebug("Launching next job..."); if(countRunningJobs() >= m_preferences->getMaxRunningJobCount()) { @@ -603,23 +740,28 @@ void MainWindow::launchNextJob(void) return; } - int startIdx= ui->jobsView->currentIndex().isValid() ? qBound(0, ui->jobsView->currentIndex().row(), rows-1) : 0; + const int rows = m_jobList->rowCount(QModelIndex()); for(int i = 0; i < rows; i++) { - int currentIdx = (i + startIdx) % rows; - JobStatus status = m_jobList->getJobStatus(m_jobList->index(currentIdx, 0, QModelIndex())); - if(status == JobStatus_Enqueued) + const QModelIndex currentIndex = m_jobList->index(i, 0, QModelIndex()); + if(m_jobList->getJobStatus(currentIndex) == JobStatus_Enqueued) { - if(m_jobList->startJob(m_jobList->index(currentIdx, 0, QModelIndex()))) + if(m_jobList->startJob(currentIndex)) { - ui->jobsView->selectRow(currentIdx); + ui->jobsView->selectRow(currentIndex.row()); return; } } } - qWarning("No enqueued jobs left!"); + qWarning("No enqueued jobs left to be started!"); + + if(m_postOperation) + { + qDebug("Post operation has been scheduled! (m_postOperation: %d)", m_postOperation); + QTimer::singleShot(0, this, SLOT(shutdownComputer())); + } } /* @@ -629,27 +771,31 @@ void MainWindow::saveLogFile(const QModelIndex &index) { if(index.isValid()) { - if(LogFileModel *log = m_jobList->getLogFile(index)) + const LogFileModel *const logData = m_jobList->getLogFile(index); + const QString &outputFilePath = m_jobList->getJobOutputFile(index); + if(logData && (!outputFilePath.isEmpty())) { - QDir(QString("%1/logs").arg(x264_data_path())).mkpath("."); - QString logFilePath = QString("%1/logs/LOG.%2.%3.txt").arg(x264_data_path(), QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString(Qt::ISODate).replace(':', "-")); - QFile outFile(logFilePath); - if(outFile.open(QIODevice::WriteOnly)) + const QFileInfo outputFileInfo(outputFilePath); + if (outputFileInfo.absoluteDir().exists()) { - QTextStream outStream(&outFile); - outStream.setCodec("UTF-8"); - outStream.setGenerateByteOrderMark(true); - - const int rows = log->rowCount(QModelIndex()); - for(int i = 0; i < rows; i++) + const QString outputDir = outputFileInfo.absolutePath(), outputName = outputFileInfo.fileName(); + const QString logFilePath = MUtils::make_unique_file(outputDir, outputName, QLatin1String("log"), true); + if (!logFilePath.isEmpty()) { - outStream << log->data(log->index(i, 0, QModelIndex()), Qt::DisplayRole).toString() << QLatin1String("\r\n"); + qDebug("Saving log file to: \"%s\"", MUTILS_UTF8(logFilePath)); + if (!logData->saveToLocalFile(logFilePath)) + { + qWarning("Failed to open log file for writing:\n%s", logFilePath.toUtf8().constData()); + } + } + else + { + qWarning("Failed to generate log file name. Giving up!"); } - outFile.close(); } else { - qWarning("Failed to open log file for writing:\n%s", logFilePath.toUtf8().constData()); + qWarning("Output directory does not seem to exist. Giving up!"); } } } @@ -660,26 +806,24 @@ void MainWindow::saveLogFile(const QModelIndex &index) */ void MainWindow::shutdownComputer(void) { - qDebug("shutdownComputer(void)"); - - if((m_status != STATUS_IDLE) && (m_status != STATUS_EXITTING)) + ENSURE_APP_IS_READY(); + qDebug("shutdownComputer (m_postOperation: %d)", m_postOperation); + + if(countPendingJobs() > 0) { - qWarning("Cannot shutdown computer at this time!"); + qWarning("Still have pending jobs, won't shutdown yet!"); return; } - if(countPendingJobs() > 0) + if ((m_postOperation != POST_OP_POWERDOWN) && (m_postOperation != POST_OP_HIBERNATE)) { - qDebug("Still have pending jobs, won't shutdown yet!"); - return; + qWarning("No post-operation has been schedule!"); } - - const x264_status_t previousStatus = m_status; - m_status = STATUS_BLOCKED; const int iTimeout = 30; const Qt::WindowFlags flags = Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowSystemMenuHint; - const QString text = QString("%1%2%1").arg(QString().fill(' ', 18), tr("Warning: Computer will shutdown in %1 seconds...")); + const bool hibernate = (m_postOperation == POST_OP_HIBERNATE); + const QString text = QString("%1%2%1").arg(QString().fill(' ', 18), hibernate ? tr("Warning: Computer will hibernate in %1 seconds...") : tr("Warning: Computer will shutdown in %1 seconds...")); qWarning("Initiating shutdown sequence!"); @@ -696,7 +840,7 @@ void MainWindow::shutdownComputer(void) QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::setOverrideCursor(Qt::WaitCursor); - x264_play_sound(IDR_WAVE1, false); + MUtils::Sound::play_sound("shutdown", false); QApplication::restoreOverrideCursor(); QTimer timer; @@ -713,22 +857,23 @@ void MainWindow::shutdownComputer(void) if(progressDialog.wasCanceled()) { progressDialog.close(); - m_status = previousStatus; return; } progressDialog.setValue(i+1); progressDialog.setLabelText(text.arg(iTimeout-i)); if(iTimeout-i == 3) progressDialog.setCancelButton(NULL); QApplication::processEvents(); - x264_play_sound(((i < iTimeout) ? IDR_WAVE2 : IDR_WAVE3), false); + MUtils::Sound::play_sound(((i < iTimeout) ? "beep" : "beep2"), false); } qWarning("Shutting down !!!"); - m_status = previousStatus; - if(x264_shutdown_computer("Simple x264 Launcher: All jobs completed, shutting down!", 10, true)) + if(MUtils::OS::shutdown_computer("Simple x264 Launcher: All jobs completed, shutting down!", 10, true, hibernate)) { - qApp->closeAllWindows(); + if (!hibernate) + { + qApp->closeAllWindows(); + } } } @@ -738,102 +883,26 @@ void MainWindow::shutdownComputer(void) */ void MainWindow::init(void) { - if(m_status != STATUS_PRE_INIT) + if(m_initialized) { qWarning("Already initialized -> skipping!"); return; } updateLabelPos(); - - //--------------------------------------- - // Create the IPC listener thread - //--------------------------------------- - - if(m_ipc->isInitialized()) - { - connect(m_ipc, SIGNAL(receivedCommand(int,QStringList,quint32)), this, SLOT(handleCommand(int,QStringList,quint32)), Qt::QueuedConnection); - m_ipc->startListening(); - } + const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments(); + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); //--------------------------------------- // Check required binaries //--------------------------------------- - - QStringList binFiles; - for(OptionsModel::EncArch arch = OptionsModel::EncArch_x32; arch <= OptionsModel::EncArch_x64; NEXT(arch)) - { - for(OptionsModel::EncVariant varnt = OptionsModel::EncVariant_LoBit; varnt <= OptionsModel::EncVariant_HiBit; NEXT(varnt)) - { - binFiles << ENC_BINARY(m_sysinfo, OptionsModel::EncType_X264, arch, varnt); - } - binFiles << AVS_BINARY(m_sysinfo, arch == OptionsModel::EncArch_x64); - } qDebug("[Validating binaries]"); - for(QStringList::ConstIterator iter = binFiles.constBegin(); iter != binFiles.constEnd(); iter++) - { - qApp->processEvents(QEventLoop::ExcludeUserInputEvents); - QFile *file = new QFile(*iter); - qDebug("%s", file->fileName().toLatin1().constData()); - if(file->open(QIODevice::ReadOnly)) - { - if(!x264_is_executable(file->fileName())) - { - QMessageBox::critical(this, tr("Invalid File!"), tr("At least on required tool is not a valid Win32 or Win64 binary:
%1

Please re-install the program in order to fix the problem!
").arg(QDir::toNativeSeparators(file->fileName())).replace("-", "−")); - qFatal(QString("Binary is invalid: %1").arg(file->fileName()).toLatin1().constData()); - X264_DELETE(file); - INIT_ERROR_EXIT(); - } - m_toolsList << file; - } - else - { - QMessageBox::critical(this, tr("File Not Found!"), tr("At least on required tool could not be found:
%1

Please re-install the program in order to fix the problem!
").arg(QDir::toNativeSeparators(file->fileName())).replace("-", "−")); - qFatal(QString("Binary not found: %1/toolset/%2").arg(m_sysinfo->getAppPath(), file->fileName()).toLatin1().constData()); - X264_DELETE(file); - INIT_ERROR_EXIT(); - } - } - qDebug(" "); - - //--------------------------------------- - // Check x265 binaries - //--------------------------------------- - - binFiles.clear(); - for(OptionsModel::EncArch arch = OptionsModel::EncArch_x32; arch <= OptionsModel::EncArch_x64; NEXT(arch)) - { - for(OptionsModel::EncVariant varnt = OptionsModel::EncVariant_LoBit; varnt <= OptionsModel::EncVariant_HiBit; NEXT(varnt)) - { - binFiles << ENC_BINARY(m_sysinfo, OptionsModel::EncType_X265, arch, varnt); - } - } - - qDebug("[Checking for x265 support]"); - bool bHaveX265 = true; - for(QStringList::ConstIterator iter = binFiles.constBegin(); iter != binFiles.constEnd(); iter++) - { - qApp->processEvents(QEventLoop::ExcludeUserInputEvents); - QFile *file = new QFile(*iter); - qDebug("%s", file->fileName().toLatin1().constData()); - if(file->open(QIODevice::ReadOnly)) - { - if(x264_is_executable(file->fileName())) - { - m_toolsList << file; - continue; - } - X264_DELETE(file); - } - bHaveX265 = false; - qWarning("x265 binaries not found or incomplete -> disable x265 support!"); - break; - } - if(bHaveX265) + QString failedPath; + if(!BinariesCheckThread::check(m_sysinfo.data(), &failedPath)) { - qDebug("x265 support is officially enabled now!"); - m_sysinfo->set256Support(true); + QMessageBox::critical(this, tr("Invalid File!"), tr("At least one tool is missing or is not a valid Win32/Win64 binary:
%1

Please re-install the program in order to fix the problem!").replace("-", "−").arg(Qt::escape(QDir::toNativeSeparators(failedPath)))); + qFatal("At least one tool is missing or is not a valid Win32/Win64 binary. Program will exit now!"); } qDebug(" "); @@ -841,7 +910,7 @@ void MainWindow::init(void) // Check for portable mode //--------------------------------------- - if(x264_portable()) + if(x264_is_portable()) { bool ok = false; static const char *data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; @@ -866,50 +935,50 @@ void MainWindow::init(void) if(rnd != val) INIT_ERROR_EXIT(); } + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); + //--------------------------------------- // Check CPU capabilities //--------------------------------------- - - const QStringList arguments = x264_arguments(); //Make sure this CPU can run x264 (requires MMX + MMXEXT/iSSE to run x264 with ASM enabled, additionally requires SSE1 for most x264 builds) - if(!m_sysinfo->hasMMXSupport()) + if(!m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_MMX)) { QMessageBox::critical(this, tr("Unsupported CPU"), tr("Sorry, but this machine is not physically capable of running x264 (with assembly).
Please get a CPU that supports at least the MMX and MMXEXT instruction sets!
"), tr("Quit")); qFatal("System does not support MMX and MMXEXT, x264 will not work !!!"); INIT_ERROR_EXIT(); } - else if(!m_sysinfo->hasSSESupport()) + else if(!m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_SSE)) { - qWarning("WARNING: System does not support SSE1, most x264 builds will not work !!!\n"); - int val = QMessageBox::warning(this, tr("Unsupported CPU"), tr("It appears that this machine does not support the SSE1 instruction set.
Thus most builds of x264 will not run on this computer at all.

Please get a CPU that supports the MMX and SSE1 instruction sets!
"), tr("Quit"), tr("Ignore")); + qWarning("WARNING: System does not support SSE (v1), x264/x265 probably will *not* work !!!\n"); + int val = QMessageBox::warning(this, tr("Unsupported CPU"), tr("It appears that this machine does not support the SSE1 instruction set.
Thus most builds of x264/x265 will not run on this computer at all.

Please get a CPU that supports the MMX and SSE1 instruction sets!
"), tr("Quit"), tr("Ignore")); if(val != 1) INIT_ERROR_EXIT(); } //Skip version check (not recommended!) - if(CLIParser::checkFlag(CLI_PARAM_SKIP_X264_CHECK, arguments)) + if(arguments.contains(CLI_PARAM_SKIP_VERSION_CHECK)) { - qWarning("x264 version check disabled, you have been warned!\n"); + qWarning("Version checks are disabled now, you have been warned!\n"); m_preferences->setSkipVersionTest(true); } //Don't abort encoding process on timeout (not recommended!) - if(CLIParser::checkFlag(CLI_PARAM_NO_DEADLOCK, arguments)) + if(arguments.contains(CLI_PARAM_NO_DEADLOCK)) { qWarning("Deadlock detection disabled, you have been warned!\n"); m_preferences->setAbortOnTimeout(false); } + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); + //--------------------------------------- // Check Avisynth support //--------------------------------------- - if(!CLIParser::checkFlag(CLI_PARAM_SKIP_AVS_CHECK, arguments)) + if(!arguments.contains(CLI_PARAM_SKIP_AVS_CHECK)) { qDebug("[Check for Avisynth support]"); - volatile double avisynthVersion = 0.0; - const int result = AvisynthCheckThread::detect(&avisynthVersion); - if(result < 0) + if(!AvisynthCheckThread::detect(m_sysinfo.data())) { QString text = tr("A critical error was encountered while checking your Avisynth version.").append("
"); text += tr("This is most likely caused by an erroneous Avisynth Plugin, please try to clean your Plugins folder!").append("
"); @@ -917,24 +986,15 @@ void MainWindow::init(void) int val = QMessageBox::critical(this, tr("Avisynth Error"), QString("%1").arg(text).replace("-", "−"), tr("Quit"), tr("Ignore")); if(val != 1) INIT_ERROR_EXIT(); } - if(result && (avisynthVersion >= 2.5)) - { - qDebug("Avisynth support is officially enabled now!"); - m_sysinfo->setAVSSupport(true); - } - else + else if((!m_sysinfo->hasAvisynth()) && (!m_preferences->getDisableWarnings())) { - if(!m_preferences->getDisableWarnings()) + QString text = tr("It appears that Avisynth is not currently installed on your computer.
Therefore Avisynth (.avs) input will not be working at all!").append("

"); + text += tr("Please download and install Avisynth:").append("
").append(LINK(avs_dl_url)); + int val = QMessageBox::warning(this, tr("Avisynth Missing"), QString("%1").arg(text).replace("-", "−"), tr("Close"), tr("Disable this Warning")); + if(val == 1) { - QString text = tr("It appears that Avisynth is not currently installed on your computer.
Therefore Avisynth (.avs) input will not be working at all!").append("

"); - text += tr("Please download and install Avisynth:").append("
").append(LINK("http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/")); - int val = QMessageBox::warning(this, tr("Avisynth Missing"), QString("%1").arg(text).replace("-", "−"), tr("Close"), tr("Disable this Warning")); - if(val == 1) - { - m_preferences->setDisableWarnings(true); - PreferencesModel::savePreferences(m_preferences); - } - + m_preferences->setDisableWarnings(true); + PreferencesModel::savePreferences(m_preferences.data()); } } qDebug(" "); @@ -944,12 +1004,10 @@ void MainWindow::init(void) // Check VapurSynth support //--------------------------------------- - if(!CLIParser::checkFlag(CLI_PARAM_SKIP_VPS_CHECK, arguments)) + if(!arguments.contains(CLI_PARAM_SKIP_VPS_CHECK)) { qDebug("[Check for VapourSynth support]"); - QString vapoursynthPath; - const int result = VapourSynthCheckThread::detect(vapoursynthPath); - if(result < 0) + if(!VapourSynthCheckThread::detect(m_sysinfo.data())) { QString text = tr("A critical error was encountered while checking your VapourSynth installation.").append("
"); text += tr("This is most likely caused by an erroneous VapourSynth Plugin, please try to clean your Filters folder!").append("
"); @@ -957,40 +1015,66 @@ void MainWindow::init(void) const int val = QMessageBox::critical(this, tr("VapourSynth Error"), QString("%1").arg(text).replace("-", "−"), tr("Quit"), tr("Ignore")); if(val != 1) INIT_ERROR_EXIT(); } - if(result && (!vapoursynthPath.isEmpty())) - { - qDebug("VapourSynth support is officially enabled now!"); - m_sysinfo->setVPSSupport(true); - m_sysinfo->setVPSPath(vapoursynthPath); - } - else + else if((!m_sysinfo->hasVapourSynth()) && (!m_preferences->getDisableWarnings())) { - if(!m_preferences->getDisableWarnings()) + QString text = tr("It appears that VapourSynth is not currently installed on your computer.
Therefore VapourSynth (.vpy) input will not be working at all!").append("

"); + text += tr("Please download and install VapourSynth (r%1 or later) for Windows:").arg(QString::number(vsynth_rev)).append("
").append(LINK(vsynth_url)).append("

"); + text += tr("Note that Python v3.4 is a prerequisite for installing VapourSynth:").append("
").append(LINK(python_url)).append("
"); + const int val = QMessageBox::warning(this, tr("VapourSynth Missing"), QString("%1").arg(text).replace("-", "−"), tr("Close"), tr("Disable this Warning")); + if(val == 1) { - QString text = tr("It appears that VapourSynth is not currently installed on your computer.
Therefore VapourSynth (.vpy) input will not be working at all!").append("

"); - text += tr("Please download and install VapourSynth for Windows (R19 or later):").append("
").append(LINK("http://www.vapoursynth.com/")).append("

"); - text += tr("Note that Python 3.3 (x86) is a prerequisite for installing VapourSynth:").append("
").append(LINK("http://www.python.org/getit/")).append("
"); - const int val = QMessageBox::warning(this, tr("VapourSynth Missing"), QString("%1").arg(text).replace("-", "−"), tr("Close"), tr("Disable this Warning")); - if(val == 1) - { - m_preferences->setDisableWarnings(true); - PreferencesModel::savePreferences(m_preferences); - } + m_preferences->setDisableWarnings(true); + PreferencesModel::savePreferences(m_preferences.data()); } } qDebug(" "); } + + //--------------------------------------- + // Create the IPC listener thread + //--------------------------------------- + + if(m_ipcChannel) + { + m_ipcThread.reset(new IPCThread_Recv(m_ipcChannel)); + connect(m_ipcThread.data(), SIGNAL(receivedCommand(int,QStringList,quint32)), this, SLOT(handleCommand(int,QStringList,quint32)), Qt::QueuedConnection); + m_ipcThread->start(); + } + + //--------------------------------------- + // Finish initialization + //--------------------------------------- + + //Set Window title + setWindowTitle(QString("%1 (%2)").arg(windowTitle(), m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64) ? "64-Bit" : "32-Bit")); + + //Enable drag&drop support for this window, required for Qt v4.8.4+ + setAcceptDrops(true); + + //Update flag + m_initialized = true; + + //Hide the spinner animation + if(!m_label[1].isNull()) + { + if(!m_animation.isNull()) + { + m_animation->stop(); + } + m_label[1]->setVisible(false); + } //--------------------------------------- // Check for Expiration //--------------------------------------- - if(x264_version_date().addMonths(6) < x264_current_date_safe()) + if(MUtils::Version::app_build_date().addMonths(6) < MUtils::OS::current_date()) { + if(QWidget *cornerWidget = ui->menubar->cornerWidget()) cornerWidget->show(); QString text; - text += QString("%1

").arg(tr("Your version of Simple x264 Launcher is more than 6 months old!").replace("-", "−")); - text += QString("%1
%2

").arg(tr("You can download the most recent version from the official web-site now:").replace("-", "−"), QString::fromLatin1(update_url)); - text += QString("
%1
").arg(tr("Alternatively, click 'Check for Updates' to run the auto-update utility.").replace("-", "−")); + text += QString("%1

").arg(tr("Your version of Simple x264 Launcher is more than 6 months old!").replace('-', "−")); + text += QString("%1
%3

").arg(tr("You can download the most recent version from the official web-site now:").replace('-', "−"), QString::fromLatin1(update_url), QString::fromLatin1(update_url).replace("-", "−")); + text += QString("
%1
").arg(tr("Alternatively, click 'Check for Updates' to run the auto-update utility.").replace('-', "−")); QMessageBox msgBox(this); msgBox.setIconPixmap(QIcon(":/images/update.png").pixmap(56,56)); msgBox.setWindowTitle(tr("Update Notification")); @@ -1005,43 +1089,37 @@ void MainWindow::init(void) QTimer::singleShot(7500, btn3, SLOT(show())); if(msgBox.exec() == 0) { - m_status = STATUS_IDLE; QTimer::singleShot(0, this, SLOT(checkUpdates())); return; } } - - //--------------------------------------- - // Finish initialization - //--------------------------------------- - - //Set Window title - setWindowTitle(QString("%1 (%2)").arg(windowTitle(), m_sysinfo->hasX64Support() ? "64-Bit" : "32-Bit")); - - //Enable drag&drop support for this window, required for Qt v4.8.4+ - setAcceptDrops(true); - - //Update app staus - m_status = STATUS_IDLE; - - //Try adding files from command-line - if(!parseCommandLineArgs()) + else if(!parseCommandLineArgs()) { //Update reminder - if((!m_preferences->getNoUpdateReminder()) && (m_recentlyUsed->lastUpdateCheck() + 14 < x264_current_date_safe().toJulianDay())) + if(arguments.contains(CLI_PARAM_FIRST_RUN)) { - if(QMessageBox::warning(this, tr("Update Notification"), QString("%1").arg(tr("Your last update check was more than 14 days ago. Check for updates now?")), tr("Check for Updates"), tr("Discard")) == 0) + qWarning("First run -> resetting update check now!"); + m_recentlyUsed->setLastUpdateCheck(0); + RecentlyUsed::saveRecentlyUsed(m_recentlyUsed.data()); + } + else if(m_recentlyUsed->lastUpdateCheck() + 14 < MUtils::OS::current_date().toJulianDay()) + { + if(QWidget *cornerWidget = ui->menubar->cornerWidget()) cornerWidget->show(); + if(!m_preferences->getNoUpdateReminder()) { - QTimer::singleShot(0, this, SLOT(checkUpdates())); - return; + if(QMessageBox::warning(this, tr("Update Notification"), QString("%1").arg(tr("Your last update check was more than 14 days ago. Check for updates now?")), tr("Check for Updates"), tr("Discard")) == 0) + { + QTimer::singleShot(0, this, SLOT(checkUpdates())); + return; + } } } } //Load queued jobs - if(m_jobList->loadQueuedJobs(m_sysinfo) > 0) + if(m_jobList->loadQueuedJobs(m_sysinfo.data()) > 0) { - m_label->setVisible(m_jobList->rowCount(QModelIndex()) == 0); + m_label[0]->setVisible(m_jobList->rowCount(QModelIndex()) == 0); m_jobList->clearQueuedJobs(); } } @@ -1051,8 +1129,15 @@ void MainWindow::init(void) */ void MainWindow::updateLabelPos(void) { - const QWidget *const viewPort = ui->jobsView->viewport(); - m_label->setGeometry(0, 0, viewPort->width(), viewPort->height()); + for(int i = 0; i < 2; i++) + { + //const QWidget *const viewPort = ui->jobsView->viewport(); + const QWidget *const viewPort = dynamic_cast(m_label[i]->parent()); + if(viewPort) + { + m_label[i]->setGeometry(0, 0, viewPort->width(), viewPort->height()); + } + } } /* @@ -1060,43 +1145,79 @@ void MainWindow::updateLabelPos(void) */ void MainWindow::copyLogToClipboard(bool checked) { - qDebug("copyLogToClipboard"); + qDebug("Coyping logfile to clipboard..."); if(LogFileModel *log = dynamic_cast(ui->logView->model())) { log->copyToClipboard(); - x264_beep(x264_beep_info); + MUtils::Sound::beep(MUtils::Sound::BEEP_NFO); } } /* - * Process the dropped files + * Save log to local file */ -void MainWindow::handlePendingFiles(void) +void MainWindow::saveLogToLocalFile(bool checked) { - if((m_status == STATUS_IDLE) || (m_status == STATUS_AWAITING)) + ENSURE_APP_IS_READY(); + + const QModelIndex index = ui->jobsView->currentIndex(); + const QString initialName = index.isValid() ? QFileInfo(m_jobList->getJobOutputFile(index)).completeBaseName() : tr("Logfile"); + const QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log File"), initialName, tr("Log File (*.log)")); + if(!fileName.isEmpty()) { - qDebug("MainWindow::handlePendingFiles"); - if(!m_pendingFiles->isEmpty()) + if(LogFileModel *log = dynamic_cast(ui->logView->model())) { - QStringList pendingFiles(*m_pendingFiles); - m_pendingFiles->clear(); - createJobMultiple(pendingFiles); + if(!log->saveToLocalFile(fileName)) + { + QMessageBox::warning(this, this->windowTitle(), tr("Error: Log file could not be saved!")); + } } - qDebug("Leave from MainWindow::handlePendingFiles!"); - m_status = STATUS_IDLE; } } +/* + * Toggle line-wrapping + */ +void MainWindow::toggleLineWrapping(bool checked) +{ + ui->logView->setWordWrap(checked); +} + +/* + * Process the dropped files + */ +void MainWindow::handlePendingFiles(void) +{ + qDebug("MainWindow::handlePendingFiles"); + + if(!m_pendingFiles->isEmpty()) + { + QStringList pendingFiles(*m_pendingFiles); + m_pendingFiles->clear(); + createJobMultiple(pendingFiles); + } + + qDebug("Leave from MainWindow::handlePendingFiles!"); +} + +/* + * Handle incoming IPC command + */ void MainWindow::handleCommand(const int &command, const QStringList &args, const quint32 &flags) { - if((m_status != STATUS_IDLE) && (m_status != STATUS_AWAITING)) + if(!(m_initialized && (QApplication::activeModalWidget() == NULL))) { qWarning("Cannot accapt commands at this time -> discarding!"); return; } - x264_bring_to_front(this); + if((!isVisible()) || m_sysTray->isVisible()) + { + sysTrayActived(); + } + + MUtils::GUI::bring_to_front(this); #ifdef IPC_LOGGING qDebug("\n---------- IPC ----------"); @@ -1113,7 +1234,7 @@ void MainWindow::handleCommand(const int &command, const QStringList &args, cons { case IPC_OPCODE_PING: qDebug("Received a PING request from another instance!"); - x264_blink_window(this, 5, 125); + MUtils::GUI::blink_window(this, 5, 125); break; case IPC_OPCODE_ADD_FILE: if(!args.isEmpty()) @@ -1121,10 +1242,10 @@ void MainWindow::handleCommand(const int &command, const QStringList &args, cons if(QFileInfo(args[0]).exists() && QFileInfo(args[0]).isFile()) { *m_pendingFiles << QFileInfo(args[0]).canonicalFilePath(); - if(m_status != STATUS_AWAITING) + if(!m_fileTimer->isActive()) { - m_status = STATUS_AWAITING; - QTimer::singleShot(5000, this, SLOT(handlePendingFiles())); + m_fileTimer->setSingleShot(true); + m_fileTimer->start(5000); } } else @@ -1138,7 +1259,7 @@ void MainWindow::handleCommand(const int &command, const QStringList &args, cons { if(QFileInfo(args[0]).exists() && QFileInfo(args[0]).isFile()) { - OptionsModel options(m_sysinfo); + OptionsModel options(m_sysinfo.data()); bool runImmediately = (countRunningJobs() < (m_preferences->getAutoRunNextJob() ? m_preferences->getMaxRunningJobCount() : 1)); if(!(args[2].isEmpty() || X264_STRCMP(args[2], "-"))) { @@ -1158,47 +1279,46 @@ void MainWindow::handleCommand(const int &command, const QStringList &args, cons } break; default: - THROW("Unknown command received!"); + MUTILS_THROW("Unknown command received!"); } } +/* + * Check for new updates + */ void MainWindow::checkUpdates(void) { - ENSURE_APP_IS_IDLE(); - m_status = STATUS_BLOCKED; + ENSURE_APP_IS_READY(); if(countRunningJobs() > 0) { QMessageBox::warning(this, tr("Jobs Are Running"), tr("Sorry, can not update while there still are running jobs!")); - m_status = STATUS_IDLE; return; } - UpdaterDialog *updater = new UpdaterDialog(this, m_sysinfo); + UpdaterDialog *updater = new UpdaterDialog(this, m_sysinfo.data(), update_url); const int ret = updater->exec(); if(updater->getSuccess()) { - m_recentlyUsed->setLastUpdateCheck(x264_current_date_safe().toJulianDay()); - RecentlyUsed::saveRecentlyUsed(m_recentlyUsed); + m_recentlyUsed->setLastUpdateCheck(MUtils::OS::current_date().toJulianDay()); + RecentlyUsed::saveRecentlyUsed(m_recentlyUsed.data()); + if(QWidget *cornerWidget = ui->menubar->cornerWidget()) cornerWidget->hide(); } if(ret == UpdaterDialog::READY_TO_INSTALL_UPDATE) { - m_status = STATUS_EXITTING; qWarning("Exitting program to install update..."); close(); QApplication::quit(); } - X264_DELETE(updater); - - if(m_status != STATUS_EXITTING) - { - m_status = STATUS_IDLE; - } + MUTILS_DELETE(updater); } +/* + * Handle mouse event for version label + */ void MainWindow::versionLabelMouseClicked(const int &tag) { if(tag == 0) @@ -1207,6 +1327,9 @@ void MainWindow::versionLabelMouseClicked(const int &tag) } } +/* + * Handle key event for job list + */ void MainWindow::jobListKeyPressed(const int &tag) { switch(tag) @@ -1220,6 +1343,16 @@ void MainWindow::jobListKeyPressed(const int &tag) } } +/* + * System tray was activated + */ +void MainWindow::sysTrayActived(void) +{ + m_sysTray->hide(); + showNormal(); + MUtils::GUI::bring_to_front(this); +} + /////////////////////////////////////////////////////////////////////////////// // Event functions /////////////////////////////////////////////////////////////////////////////// @@ -1231,7 +1364,7 @@ void MainWindow::showEvent(QShowEvent *e) { QMainWindow::showEvent(e); - if(m_status == STATUS_PRE_INIT) + if(!m_initialized) { QTimer::singleShot(0, this, SLOT(init())); } @@ -1242,7 +1375,7 @@ void MainWindow::showEvent(QShowEvent *e) */ void MainWindow::closeEvent(QCloseEvent *e) { - if((m_status != STATUS_IDLE) && (m_status != STATUS_EXITTING)) + if(!APP_IS_READY) { e->ignore(); qWarning("Cannot close window at this time!"); @@ -1250,36 +1383,42 @@ void MainWindow::closeEvent(QCloseEvent *e) } //Make sure we have no running jobs left! - if(m_status != STATUS_EXITTING) + if(countRunningJobs() > 0) { - if(countRunningJobs() > 0) + e->ignore(); + if(!m_preferences->getNoSystrayWarning()) { - e->ignore(); - m_status = STATUS_BLOCKED; - QMessageBox::warning(this, tr("Jobs Are Running"), tr("Sorry, can not exit while there still are running jobs!")); - m_status = STATUS_IDLE; - return; + if(QMessageBox::warning(this, tr("Jobs Are Running"), tr("You still have running jobs, application will be minimized to notification area!"), tr("OK"), tr("Don't Show Again")) == 1) + { + m_preferences->setNoSystrayWarning(true); + PreferencesModel::savePreferences(m_preferences.data()); + } } + hide(); + m_sysTray->show(); + return; + } - //Save pending jobs for next time, if desired by user - if(countPendingJobs() > 0) + //Save pending jobs for next time, if desired by user + if(countPendingJobs() > 0) + { + if (!m_preferences->getSaveQueueNoConfirm()) { - m_status = STATUS_BLOCKED; - int ret = QMessageBox::question(this, tr("Jobs Are Pending"), tr("You still have pending jobs. How do you want to proceed?"), tr("Save Pending Jobs"), tr("Discard")); - if(ret == 0) - { - m_jobList->saveQueuedJobs(); - } - else + const int ret = QMessageBox::question(this, tr("Jobs Are Pending"), tr("You still have some pending jobs in your queue. How do you want to proceed?"), tr("Save Jobs"), tr("Always Save Jobs"), tr("Discard Jobs")); + if ((ret >= 0) && (ret <= 1)) { - if(QMessageBox::warning(this, tr("Jobs Are Pending"), tr("Do you really want to discard all pending jobs?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) + if (ret > 0) { - e->ignore(); - m_status = STATUS_IDLE; - return; + m_preferences->setSaveQueueNoConfirm(true); + PreferencesModel::savePreferences(m_preferences.data()); } + m_jobList->saveQueuedJobs(); } } + else + { + m_jobList->saveQueuedJobs(); + } } //Delete remaining jobs @@ -1292,13 +1431,10 @@ void MainWindow::closeEvent(QCloseEvent *e) if(!m_jobList->deleteJob(m_jobList->index(0, 0, QModelIndex()))) { e->ignore(); - m_status = STATUS_BLOCKED; QMessageBox::warning(this, tr("Failed To Exit"), tr("Warning: At least one job could not be deleted!")); - m_status = STATUS_IDLE; } } - m_status = STATUS_EXITTING; qApp->processEvents(QEventLoop::ExcludeUserInputEvents); QMainWindow::closeEvent(e); } @@ -1313,14 +1449,6 @@ void MainWindow::resizeEvent(QResizeEvent *e) } /* - * Win32 message filter - */ -bool MainWindow::winEvent(MSG *message, long *result) -{ - return WinSevenTaskbar::handleWinEvent(message, result); -} - -/* * File dragged over window */ void MainWindow::dragEnterEvent(QDragEnterEvent *event) @@ -1344,9 +1472,9 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event) */ void MainWindow::dropEvent(QDropEvent *event) { - if((m_status != STATUS_IDLE) && (m_status != STATUS_AWAITING)) + if(!(m_initialized && (QApplication::activeModalWidget() == NULL))) { - qWarning("Cannot accept drooped files at this time -> discarding!"); + qWarning("Cannot accept dropped files at this time -> discarding!"); return; } @@ -1368,10 +1496,10 @@ void MainWindow::dropEvent(QDropEvent *event) { m_pendingFiles->append(droppedFiles); m_pendingFiles->sort(); - if(m_status != STATUS_AWAITING) + if(!m_fileTimer->isActive()) { - m_status = STATUS_AWAITING; - QTimer::singleShot(0, this, SLOT(handlePendingFiles())); + m_fileTimer->setSingleShot(true); + m_fileTimer->start(5000); } } } @@ -1386,7 +1514,7 @@ void MainWindow::dropEvent(QDropEvent *event) bool MainWindow::createJob(QString &sourceFileName, QString &outputFileName, OptionsModel *options, bool &runImmediately, const bool restart, int fileNo, int fileTotal, bool *applyToAll) { bool okay = false; - AddJobDialog *addDialog = new AddJobDialog(this, options, m_recentlyUsed, m_sysinfo, m_preferences); + AddJobDialog *addDialog = new AddJobDialog(this, options, m_recentlyUsed.data(), m_sysinfo.data(), m_preferences.data()); addDialog->setRunImmediately(runImmediately); if(!sourceFileName.isEmpty()) addDialog->setSourceFile(sourceFileName); @@ -1413,7 +1541,7 @@ bool MainWindow::createJob(QString &sourceFileName, QString &outputFileName, Opt okay = true; } - X264_DELETE(addDialog); + MUTILS_DELETE(addDialog); return okay; } @@ -1431,9 +1559,9 @@ bool MainWindow::createJobMultiple(const QStringList &filePathIn) { runImmediately = (countRunningJobs() < (m_preferences->getAutoRunNextJob() ? m_preferences->getMaxRunningJobCount() : 1)); QString sourceFileName(*iter), outputFileName; - if(createJob(sourceFileName, outputFileName, m_options, runImmediately, false, counter++, filePathIn.count(), &applyToAll)) + if(createJob(sourceFileName, outputFileName, m_options.data(), runImmediately, false, counter++, filePathIn.count(), &applyToAll)) { - if(appendJob(sourceFileName, outputFileName, m_options, runImmediately)) + if(appendJob(sourceFileName, outputFileName, m_options.data(), runImmediately)) { continue; } @@ -1447,7 +1575,7 @@ bool MainWindow::createJobMultiple(const QStringList &filePathIn) const bool runImmediatelyTmp = runImmediately && (countRunningJobs() < (m_preferences->getAutoRunNextJob() ? m_preferences->getMaxRunningJobCount() : 1)); const QString sourceFileName = *iter; const QString outputFileName = AddJobDialog::generateOutputFileName(sourceFileName, m_recentlyUsed->outputDirectory(), m_recentlyUsed->filterIndex(), m_preferences->getSaveToSourcePath()); - if(!appendJob(sourceFileName, outputFileName, m_options, runImmediatelyTmp)) + if(!appendJob(sourceFileName, outputFileName, m_options.data(), runImmediatelyTmp)) { return false; } @@ -1463,7 +1591,7 @@ bool MainWindow::createJobMultiple(const QStringList &filePathIn) bool MainWindow::appendJob(const QString &sourceFileName, const QString &outputFileName, OptionsModel *options, const bool runImmediately) { bool okay = false; - EncodeThread *thrd = new EncodeThread(sourceFileName, outputFileName, options, m_sysinfo, m_preferences); + EncodeThread *thrd = new EncodeThread(sourceFileName, outputFileName, options, m_sysinfo.data(), m_preferences.data()); QModelIndex newIndex = m_jobList->insertJob(thrd); if(newIndex.isValid()) @@ -1478,7 +1606,7 @@ bool MainWindow::appendJob(const QString &sourceFileName, const QString &outputF okay = true; } - m_label->setVisible(m_jobList->rowCount(QModelIndex()) == 0); + m_label[0]->setVisible(m_jobList->rowCount(QModelIndex()) == 0); return okay; } @@ -1555,26 +1683,31 @@ void MainWindow::updateTaskbar(JobStatus status, const QIcon &icon) { qDebug("MainWindow::updateTaskbar(void)"); + if(m_taskbar.isNull()) + { + return; /*taskbar object not created yet*/ + } + switch(status) { case JobStatus_Undefined: - WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNoState); + m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NONE); break; case JobStatus_Aborting: case JobStatus_Starting: case JobStatus_Pausing: case JobStatus_Resuming: - WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarIndeterminateState); + m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_INTERMEDIATE); break; case JobStatus_Aborted: case JobStatus_Failed: - WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState); + m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_ERROR); break; case JobStatus_Paused: - WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarPausedState); + m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_PAUSED); break; default: - WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState); + m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NORMAL); break; } @@ -1586,11 +1719,11 @@ void MainWindow::updateTaskbar(JobStatus status, const QIcon &icon) case JobStatus_Resuming: break; default: - WinSevenTaskbar::setTaskbarProgress(this, ui->progressBar->value(), ui->progressBar->maximum()); + m_taskbar->setTaskbarProgress(ui->progressBar->value(), ui->progressBar->maximum()); break; } - WinSevenTaskbar::setOverlayIcon(this, icon.isNull() ? NULL : &icon); + m_taskbar->setOverlayIcon(icon.isNull() ? NULL : &icon); } /* @@ -1598,41 +1731,46 @@ void MainWindow::updateTaskbar(JobStatus status, const QIcon &icon) */ bool MainWindow::parseCommandLineArgs(void) { - bool bCommandAccepted = false; - unsigned int flags = 0; + const MUtils::OS::ArgumentMap &args = MUtils::OS::arguments(); - //Initialize command-line parser - CLIParser parser(x264_arguments()); - int identifier; - QStringList options; + quint32 flags = 0; + bool commandSent = false; + + //Handle flags + if(args.contains(CLI_PARAM_FORCE_START)) + { + flags = ((flags | IPC_FLAG_FORCE_START) & (~IPC_FLAG_FORCE_ENQUEUE)); + } + if(args.contains(CLI_PARAM_FORCE_ENQUEUE)) + { + flags = ((flags | IPC_FLAG_FORCE_ENQUEUE) & (~IPC_FLAG_FORCE_START)); + } //Process all command-line arguments - while(parser.nextOption(identifier, &options)) + if(args.contains(CLI_PARAM_ADD_FILE)) + { + foreach(const QString &fileName, args.values(CLI_PARAM_ADD_FILE)) + { + handleCommand(IPC_OPCODE_ADD_FILE, QStringList() << fileName, flags); + } + commandSent = true; + } + if(args.contains(CLI_PARAM_ADD_JOB)) { - switch(identifier) + foreach(const QString &options, args.values(CLI_PARAM_ADD_JOB)) { - case CLI_PARAM_ADD_FILE: - handleCommand(IPC_OPCODE_ADD_FILE, options, flags); - bCommandAccepted = true; - break; - case CLI_PARAM_ADD_JOB: - handleCommand(IPC_OPCODE_ADD_JOB, options, flags); - bCommandAccepted = true; - break; - case CLI_PARAM_FORCE_START: - flags = ((flags | IPC_FLAG_FORCE_START) & (~IPC_FLAG_FORCE_ENQUEUE)); - break; - case CLI_PARAM_NO_FORCE_START: - flags = (flags & (~IPC_FLAG_FORCE_START)); - break; - case CLI_PARAM_FORCE_ENQUEUE: - flags = ((flags | IPC_FLAG_FORCE_ENQUEUE) & (~IPC_FLAG_FORCE_START)); - break; - case CLI_PARAM_NO_FORCE_ENQUEUE: - flags = (flags & (~IPC_FLAG_FORCE_ENQUEUE)); - break; + const QStringList optionValues = options.split('|', QString::SkipEmptyParts); + if(optionValues.count() == 3) + { + handleCommand(IPC_OPCODE_ADD_JOB, optionValues, flags); + } + else + { + qWarning("Invalid number of arguments for parameter \"--%s\" detected!", CLI_PARAM_ADD_JOB); + } } + commandSent = true; } - return bCommandAccepted; + return commandSent; }