Browse Source

- Simplified file preview using QDesktopServices

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
5b6166ee15
  1. 4
      src/FinishedTorrents.cpp
  2. 27
      src/GUI.cpp
  3. 3
      src/GUI.h
  4. 4
      src/downloadingTorrents.cpp
  5. 45
      src/options.ui
  6. 16
      src/options_imp.cpp
  7. 2
      src/options_imp.h

4
src/FinishedTorrents.cpp

@ -320,8 +320,6 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){ @@ -320,8 +320,6 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){
QModelIndex index;
// Enable/disable pause/start action given the DL state
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
QSettings settings("qBittorrent", "qBittorrent");
QString previewProgram = settings.value("Preferences/general/MediaPlayer", QString()).toString();
bool has_pause = false, has_start = false, has_preview = false;
foreach(index, selectedIndexes) {
if(index.column() == F_NAME) {
@ -341,7 +339,7 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){ @@ -341,7 +339,7 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){
has_pause = true;
}
}
if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(hash) && !has_preview) {
if(BTSession->isFilePreviewPossible(hash) && !has_preview) {
myFinishedListMenu.addAction(actionPreview_file);
has_preview = true;
}

27
src/GUI.cpp

@ -160,8 +160,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis @@ -160,8 +160,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
checkConnect = new QTimer(this);
connect(checkConnect, SIGNAL(timeout()), this, SLOT(checkConnectionStatus()));
checkConnect->start(5000);
previewProcess = new QProcess(this);
connect(previewProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(cleanTempPreviewFile(int, QProcess::ExitStatus)));
// Accept drag 'n drops
setAcceptDrops(true);
if(!settings.value(QString::fromUtf8("Preferences/General/StartMinimized"), false).toBool()) {
@ -185,9 +183,6 @@ GUI::~GUI() { @@ -185,9 +183,6 @@ GUI::~GUI() {
delete myTrayIconMenu;
}
delete tcpServer;
previewProcess->kill();
previewProcess->waitForFinished();
delete previewProcess;
delete connecStatusLblIcon;
delete tabs;
// Keyboard shortcuts
@ -391,12 +386,6 @@ void GUI::on_actionPreview_file_triggered() { @@ -391,12 +386,6 @@ void GUI::on_actionPreview_file_triggered() {
new previewSelect(this, h);
}
void GUI::cleanTempPreviewFile(int, QProcess::ExitStatus) const {
if(!QFile::remove(QDir::tempPath()+QDir::separator()+QString::fromUtf8("qBT_preview.tmp"))) {
std::cerr << "Couldn't remove temporary file: " << (QDir::tempPath()+QDir::separator()+QString::fromUtf8("qBT_preview.tmp")).toUtf8().data() << "\n";
}
}
// Necessary if we want to close the window
// in one time if "close to systray" is enabled
void GUI::on_actionExit_triggered() {
@ -405,21 +394,7 @@ void GUI::on_actionExit_triggered() { @@ -405,21 +394,7 @@ void GUI::on_actionExit_triggered() {
}
void GUI::previewFile(QString filePath) {
// Check if there is already one preview running
if(previewProcess->state() == QProcess::NotRunning) {
// First copy temporarily (XXX: is it necessary?)
QString tmpPath = QDir::tempPath()+QDir::separator()+QString::fromUtf8("qBT_preview.tmp");
QFile::remove(tmpPath);
QFile::copy(filePath, tmpPath);
// Launch program preview
QStringList params;
params << tmpPath;
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QString previewProgram = settings.value(QString::fromUtf8("Preferences/General/MediaPlayer"), QString()).toString();
previewProcess->start(previewProgram, params, QIODevice::ReadOnly);
}else{
QMessageBox::critical(0, tr("Preview process already running"), tr("There is already another preview process running.\nPlease close the other one first."));
}
QDesktopServices::openUrl(filePath);
}
unsigned int GUI::getCurrentTabIndex() const{

3
src/GUI.h

@ -74,8 +74,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -74,8 +74,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
QShortcut *switchDownShortcut;
QShortcut *switchUpShortcut;
QShortcut *switchRSSShortcut;
// Preview
QProcess *previewProcess;
// Search
SearchEngine *searchEngine;
// RSS
@ -99,7 +97,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -99,7 +97,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void torrentDoubleClicked(QString hash, bool finished);
void on_actionPreview_file_triggered();
void previewFile(QString filePath);
void cleanTempPreviewFile(int, QProcess::ExitStatus) const;
void balloonClicked();
void writeSettings();
void readSettings();

4
src/downloadingTorrents.cpp

@ -253,8 +253,6 @@ void DownloadingTorrents::displayDLListMenu(const QPoint& pos) { @@ -253,8 +253,6 @@ void DownloadingTorrents::displayDLListMenu(const QPoint& pos) {
QModelIndex index;
// Enable/disable pause/start action given the DL state
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes();
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QString previewProgram = settings.value(QString::fromUtf8("Preferences/general/MediaPlayer"), QString()).toString();
bool has_pause = false, has_start = false, has_preview = false;
foreach(index, selectedIndexes) {
if(index.column() == NAME) {
@ -274,7 +272,7 @@ void DownloadingTorrents::displayDLListMenu(const QPoint& pos) { @@ -274,7 +272,7 @@ void DownloadingTorrents::displayDLListMenu(const QPoint& pos) {
has_pause = true;
}
}
if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(hash) && !has_preview) {
if(BTSession->isFilePreviewPossible(hash) && !has_preview) {
myDLLlistMenu.addAction(actionPreview_file);
has_preview = true;
}

45
src/options.ui

@ -313,51 +313,6 @@ @@ -313,51 +313,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="previewBox" >
<property name="title" >
<string>Preview program</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="lbl_preview" >
<property name="text" >
<string>Media player:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="textMediaPlayer" />
</item>
<item>
<widget class="QToolButton" name="browsePreviewButton" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >

16
src/options_imp.cpp

@ -155,7 +155,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -155,7 +155,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
connect(checkMinimizeToSysTray, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
connect(checkStartMinimized, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
connect(checkSystrayBalloons, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
connect(textMediaPlayer, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
// Downloads tab
connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkPreallocateAll, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
@ -266,7 +265,6 @@ void options_imp::saveOptions(){ @@ -266,7 +265,6 @@ void options_imp::saveOptions(){
settings.setValue(QString::fromUtf8("MinimizeToTray"), minimizeToTray());
settings.setValue(QString::fromUtf8("StartMinimized"), startMinimized());
settings.setValue(QString::fromUtf8("NotificationBaloons"), OSDEnabled());
settings.setValue(QString::fromUtf8("MediaPlayer"), getPreviewProgram());
// End General preferences
settings.endGroup();
// Downloads preferences
@ -413,7 +411,6 @@ void options_imp::loadOptions(){ @@ -413,7 +411,6 @@ void options_imp::loadOptions(){
checkStartMinimized->setChecked(settings.value(QString::fromUtf8("StartMinimized"), false).toBool());
checkSystrayBalloons->setChecked(settings.value(QString::fromUtf8("NotificationBaloons"), true).toBool());
}
textMediaPlayer->setText(settings.value(QString::fromUtf8("MediaPlayer"), QString()).toString());
// End General preferences
settings.endGroup();
// Downloads preferences
@ -593,12 +590,6 @@ int options_imp::getEncryptionSetting() const{ @@ -593,12 +590,6 @@ int options_imp::getEncryptionSetting() const{
return comboEncryption->currentIndex();
}
QString options_imp::getPreviewProgram() const{
QString preview_txt = textMediaPlayer->text();
preview_txt = preview_txt.trimmed();
return preview_txt;
}
bool options_imp::minimizeToTray() const{
if(checkNoSystray->isChecked()) return false;
return checkMinimizeToSysTray->isChecked();
@ -1025,13 +1016,6 @@ void options_imp::on_browseFilterButton_clicked() { @@ -1025,13 +1016,6 @@ void options_imp::on_browseFilterButton_clicked() {
}
}
void options_imp::on_browsePreviewButton_clicked() {
QString program_txt = QFileDialog::getOpenFileName(this, tr("Choose your favourite preview program"), QDir::homePath());
if(!program_txt.isNull()){
textMediaPlayer->setText(program_txt);
}
}
// Display dialog to choose save dir
void options_imp::on_browseSaveDirButton_clicked(){
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());

2
src/options_imp.h

@ -73,7 +73,6 @@ class options_imp : public QDialog, private Ui::Dialog { @@ -73,7 +73,6 @@ class options_imp : public QDialog, private Ui::Dialog {
bool closeToTray() const;
bool startMinimized() const;
bool OSDEnabled() const;
QString getPreviewProgram() const;
// Downloads
QString getSavePath() const;
bool preAllocateAllFiles() const;
@ -133,7 +132,6 @@ class options_imp : public QDialog, private Ui::Dialog { @@ -133,7 +132,6 @@ class options_imp : public QDialog, private Ui::Dialog {
void on_addFilterRangeButton_clicked();
void on_delFilterRangeButton_clicked();
void on_browseScanDirButton_clicked();
void on_browsePreviewButton_clicked();
void on_browseFilterButton_clicked();
void on_browseSaveDirButton_clicked();
void processFilterFile(QString filePath=QString());

Loading…
Cancel
Save