From 8e4e3814081edfe8c7e160ec804b8ebb7101888f Mon Sep 17 00:00:00 2001 From: lordmulder Date: Mon, 23 Mar 2015 21:22:11 +0100 Subject: [PATCH] Added option to enable line-wrapping + added option for saving the log to file. --- res/buttons/text_wrapping.png | Bin 0 -> 271 bytes res/resources.qrc | 1 + src/model_logFile.cpp | 32 +++++++++++++++++++++ src/model_logFile.h | 1 + src/version.h | 2 +- src/win_main.cpp | 52 ++++++++++++++++++++++++++++++++-- src/win_main.h | 2 ++ 7 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 res/buttons/text_wrapping.png diff --git a/res/buttons/text_wrapping.png b/res/buttons/text_wrapping.png new file mode 100644 index 0000000000000000000000000000000000000000..106edae52ddaf5828f2c13d9a3f0b765348ca360 GIT binary patch literal 271 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-$x=;`7ZqH#X?&-n&<1H*t-4XiFA z|NbBT(EiX|;vdt)=eL)BYkFIjmhz*Y`Q6X|5C6~m|6fsU$^Z73Y=>6wm*9Kh(DR>v zbCQ~}+3o+zcLe_a7x%GevD>fob^b$n0Vh$N)FaE}JsaQGtK1E*H@?HT>!JMN_?D)# z5k5cKbDC@?aVGq?saOBXe{&-H#$Ak_jf_{s6YhrpH>hE3KU}$i$*n6{nBfgu*1H&+ Sq+p<989ZJ6T-G@yGywo4ifyU@ literal 0 HcmV?d00001 diff --git a/res/resources.qrc b/res/resources.qrc index 87e0c07..7ca3305 100644 --- a/res/resources.qrc +++ b/res/resources.qrc @@ -46,6 +46,7 @@ buttons/shield_green.png buttons/shield_grey.png buttons/suspended.png + buttons/text_wrapping.png buttons/transmit.png buttons/trash.png buttons/update.png diff --git a/src/model_logFile.cpp b/src/model_logFile.cpp index c16edb2..b0a50aa 100644 --- a/src/model_logFile.cpp +++ b/src/model_logFile.cpp @@ -26,6 +26,7 @@ #include #include #include +#include LogFileModel::LogFileModel(const QString &sourceName, const QString &outputName, const QString &configName) { @@ -92,6 +93,37 @@ void LogFileModel::copyToClipboard(void) clipboard->setText(m_lines.join("\r\n")); } +bool LogFileModel::saveToLocalFile(const QString &fileName) +{ + QFile file(fileName); + if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) + { + return false; + } + + QTextStream out(&file); + out.setCodec("UTF-8"); + for(QStringList::ConstIterator iter = m_lines.constBegin(); iter != m_lines.constEnd(); iter++) + { + out << (*iter) << QLatin1String("\r\n"); + if(out.status() != QTextStream::Status::Ok) + { + file.close(); + return false; + } + } + + out.flush(); + if(out.status() != QTextStream::Status::Ok) + { + file.close(); + return false; + } + + file.close(); + return true; +} + /////////////////////////////////////////////////////////////////////////////// // Slots /////////////////////////////////////////////////////////////////////////////// diff --git a/src/model_logFile.h b/src/model_logFile.h index 1bf9d6e..e2bb62f 100644 --- a/src/model_logFile.h +++ b/src/model_logFile.h @@ -44,6 +44,7 @@ public: virtual QVariant data(const QModelIndex &index, int role) const; void copyToClipboard(void); + bool saveToLocalFile(const QString &fileName); protected: QStringList m_lines; diff --git a/src/version.h b/src/version.h index f197345..45298cd 100644 --- a/src/version.h +++ b/src/version.h @@ -26,7 +26,7 @@ #define VER_X264_MAJOR 2 #define VER_X264_MINOR 5 #define VER_X264_PATCH 0 -#define VER_X264_BUILD 940 +#define VER_X264_BUILD 944 #define VER_X264_PORTABLE_EDITION (0) diff --git a/src/win_main.cpp b/src/win_main.cpp index 0681324..3ecb53a 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -187,9 +187,21 @@ MainWindow::MainWindow(const MUtils::CPUFetaures::cpu_info_t &cpuFeatures, MUtil //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 @@ -497,7 +509,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)); @@ -508,7 +523,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); @@ -1036,6 +1054,36 @@ void MainWindow::copyLogToClipboard(bool checked) } } +/* + * Save log to local file + */ +void MainWindow::saveLogToLocalFile(bool checked) +{ + 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()) + { + if(LogFileModel *log = dynamic_cast(ui->logView->model())) + { + if(!log->saveToLocalFile(fileName)) + { + QMessageBox::warning(this, this->windowTitle(), tr("Error: Log file could not be saved!")); + } + } + } +} + +/* + * Toggle line-wrapping + */ +void MainWindow::toggleLineWrapping(bool checked) +{ + ui->logView->setWordWrap(checked); +} + /* * Process the dropped files */ diff --git a/src/win_main.h b/src/win_main.h index c022758..e145798 100644 --- a/src/win_main.h +++ b/src/win_main.h @@ -116,6 +116,8 @@ private slots: void browseButtonPressed(void); void deleteButtonPressed(void); void copyLogToClipboard(bool checked); + void saveLogToLocalFile(bool checked); + void toggleLineWrapping(bool checked); void checkUpdates(void); void handlePendingFiles(void); void init(void);