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){
QModelIndex index; QModelIndex index;
// Enable/disable pause/start action given the DL state // Enable/disable pause/start action given the DL state
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); 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; bool has_pause = false, has_start = false, has_preview = false;
foreach(index, selectedIndexes) { foreach(index, selectedIndexes) {
if(index.column() == F_NAME) { if(index.column() == F_NAME) {
@ -341,7 +339,7 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){
has_pause = true; has_pause = true;
} }
} }
if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(hash) && !has_preview) { if(BTSession->isFilePreviewPossible(hash) && !has_preview) {
myFinishedListMenu.addAction(actionPreview_file); myFinishedListMenu.addAction(actionPreview_file);
has_preview = true; has_preview = true;
} }

27
src/GUI.cpp

@ -160,8 +160,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
checkConnect = new QTimer(this); checkConnect = new QTimer(this);
connect(checkConnect, SIGNAL(timeout()), this, SLOT(checkConnectionStatus())); connect(checkConnect, SIGNAL(timeout()), this, SLOT(checkConnectionStatus()));
checkConnect->start(5000); checkConnect->start(5000);
previewProcess = new QProcess(this);
connect(previewProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(cleanTempPreviewFile(int, QProcess::ExitStatus)));
// Accept drag 'n drops // Accept drag 'n drops
setAcceptDrops(true); setAcceptDrops(true);
if(!settings.value(QString::fromUtf8("Preferences/General/StartMinimized"), false).toBool()) { if(!settings.value(QString::fromUtf8("Preferences/General/StartMinimized"), false).toBool()) {
@ -185,9 +183,6 @@ GUI::~GUI() {
delete myTrayIconMenu; delete myTrayIconMenu;
} }
delete tcpServer; delete tcpServer;
previewProcess->kill();
previewProcess->waitForFinished();
delete previewProcess;
delete connecStatusLblIcon; delete connecStatusLblIcon;
delete tabs; delete tabs;
// Keyboard shortcuts // Keyboard shortcuts
@ -391,12 +386,6 @@ void GUI::on_actionPreview_file_triggered() {
new previewSelect(this, h); 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 // Necessary if we want to close the window
// in one time if "close to systray" is enabled // in one time if "close to systray" is enabled
void GUI::on_actionExit_triggered() { void GUI::on_actionExit_triggered() {
@ -405,21 +394,7 @@ void GUI::on_actionExit_triggered() {
} }
void GUI::previewFile(QString filePath) { void GUI::previewFile(QString filePath) {
// Check if there is already one preview running QDesktopServices::openUrl(filePath);
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."));
}
} }
unsigned int GUI::getCurrentTabIndex() const{ unsigned int GUI::getCurrentTabIndex() const{

3
src/GUI.h

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

4
src/downloadingTorrents.cpp

@ -253,8 +253,6 @@ void DownloadingTorrents::displayDLListMenu(const QPoint& pos) {
QModelIndex index; QModelIndex index;
// Enable/disable pause/start action given the DL state // Enable/disable pause/start action given the DL state
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); 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; bool has_pause = false, has_start = false, has_preview = false;
foreach(index, selectedIndexes) { foreach(index, selectedIndexes) {
if(index.column() == NAME) { if(index.column() == NAME) {
@ -274,7 +272,7 @@ void DownloadingTorrents::displayDLListMenu(const QPoint& pos) {
has_pause = true; has_pause = true;
} }
} }
if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(hash) && !has_preview) { if(BTSession->isFilePreviewPossible(hash) && !has_preview) {
myDLLlistMenu.addAction(actionPreview_file); myDLLlistMenu.addAction(actionPreview_file);
has_preview = true; has_preview = true;
} }

45
src/options.ui

@ -313,51 +313,6 @@
</layout> </layout>
</widget> </widget>
</item> </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> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >

16
src/options_imp.cpp

@ -155,7 +155,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
connect(checkMinimizeToSysTray, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkMinimizeToSysTray, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
connect(checkStartMinimized, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkStartMinimized, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
connect(checkSystrayBalloons, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkSystrayBalloons, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
connect(textMediaPlayer, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
// Downloads tab // Downloads tab
connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkPreallocateAll, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkPreallocateAll, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
@ -266,7 +265,6 @@ void options_imp::saveOptions(){
settings.setValue(QString::fromUtf8("MinimizeToTray"), minimizeToTray()); settings.setValue(QString::fromUtf8("MinimizeToTray"), minimizeToTray());
settings.setValue(QString::fromUtf8("StartMinimized"), startMinimized()); settings.setValue(QString::fromUtf8("StartMinimized"), startMinimized());
settings.setValue(QString::fromUtf8("NotificationBaloons"), OSDEnabled()); settings.setValue(QString::fromUtf8("NotificationBaloons"), OSDEnabled());
settings.setValue(QString::fromUtf8("MediaPlayer"), getPreviewProgram());
// End General preferences // End General preferences
settings.endGroup(); settings.endGroup();
// Downloads preferences // Downloads preferences
@ -413,7 +411,6 @@ void options_imp::loadOptions(){
checkStartMinimized->setChecked(settings.value(QString::fromUtf8("StartMinimized"), false).toBool()); checkStartMinimized->setChecked(settings.value(QString::fromUtf8("StartMinimized"), false).toBool());
checkSystrayBalloons->setChecked(settings.value(QString::fromUtf8("NotificationBaloons"), true).toBool()); checkSystrayBalloons->setChecked(settings.value(QString::fromUtf8("NotificationBaloons"), true).toBool());
} }
textMediaPlayer->setText(settings.value(QString::fromUtf8("MediaPlayer"), QString()).toString());
// End General preferences // End General preferences
settings.endGroup(); settings.endGroup();
// Downloads preferences // Downloads preferences
@ -593,12 +590,6 @@ int options_imp::getEncryptionSetting() const{
return comboEncryption->currentIndex(); 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{ bool options_imp::minimizeToTray() const{
if(checkNoSystray->isChecked()) return false; if(checkNoSystray->isChecked()) return false;
return checkMinimizeToSysTray->isChecked(); return checkMinimizeToSysTray->isChecked();
@ -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 // Display dialog to choose save dir
void options_imp::on_browseSaveDirButton_clicked(){ void options_imp::on_browseSaveDirButton_clicked(){
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath()); 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 {
bool closeToTray() const; bool closeToTray() const;
bool startMinimized() const; bool startMinimized() const;
bool OSDEnabled() const; bool OSDEnabled() const;
QString getPreviewProgram() const;
// Downloads // Downloads
QString getSavePath() const; QString getSavePath() const;
bool preAllocateAllFiles() const; bool preAllocateAllFiles() const;
@ -133,7 +132,6 @@ class options_imp : public QDialog, private Ui::Dialog {
void on_addFilterRangeButton_clicked(); void on_addFilterRangeButton_clicked();
void on_delFilterRangeButton_clicked(); void on_delFilterRangeButton_clicked();
void on_browseScanDirButton_clicked(); void on_browseScanDirButton_clicked();
void on_browsePreviewButton_clicked();
void on_browseFilterButton_clicked(); void on_browseFilterButton_clicked();
void on_browseSaveDirButton_clicked(); void on_browseSaveDirButton_clicked();
void processFilterFile(QString filePath=QString()); void processFilterFile(QString filePath=QString());

Loading…
Cancel
Save