Browse Source

- Improved download list popup menu code

- Added some asserts
- bit of code improvement/clean up
adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
6dd78d33ab
  1. 1
      TODO
  2. 39
      src/GUI.cpp
  3. 4
      src/GUI.h

1
TODO

@ -32,6 +32,7 @@
- Web interface (turbogears?) - Web interface (turbogears?)
- improve and test tracker authentication code (remember login/pass) - improve and test tracker authentication code (remember login/pass)
- support zipped torrents? - support zipped torrents?
- Split Download list / GUI code
// in v1.0.0 (partial) - WIP // in v1.0.0 (partial) - WIP
- Check storage st creation + hasher in torrent creation - Check storage st creation + hasher in torrent creation

39
src/GUI.cpp

@ -389,6 +389,7 @@ void GUI::on_actionSet_download_limit_triggered(){
hashes << DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); hashes << DLListModel->data(DLListModel->index(index.row(), HASH)).toString();
} }
} }
Q_ASSERT(hashes.size() > 0);
new BandwidthAllocationDialog(this, false, BTSession, hashes); new BandwidthAllocationDialog(this, false, BTSession, hashes);
} }
@ -402,10 +403,11 @@ void GUI::on_actionSet_upload_limit_triggered(){
hashes << DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); hashes << DLListModel->data(DLListModel->index(index.row(), HASH)).toString();
} }
} }
Q_ASSERT(hashes.size() > 0);
new BandwidthAllocationDialog(this, true, BTSession, hashes); new BandwidthAllocationDialog(this, true, BTSession, hashes);
} }
void GUI::handleDownloadFromUrlFailure(QString url, QString reason){ void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
// Display a message box // Display a message box
QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download file at url: %1, reason: %2.").arg(url).arg(reason)); QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download file at url: %1, reason: %2.").arg(url).arg(reason));
} }
@ -423,7 +425,7 @@ void GUI::on_actionSet_global_download_limit_triggered(){
void GUI::on_actionPreview_file_triggered(){ void GUI::on_actionPreview_file_triggered(){
if(tabs->currentIndex() > 1) return; if(tabs->currentIndex() > 1) return;
bool inDownloadList = true; bool inDownloadList = true;
if(tabs->currentIndex() != 0) if(tabs->currentIndex())
inDownloadList = false; inDownloadList = false;
QModelIndex index; QModelIndex index;
QModelIndexList selectedIndexes; QModelIndexList selectedIndexes;
@ -447,7 +449,9 @@ void GUI::on_actionPreview_file_triggered(){
} }
void GUI::cleanTempPreviewFile(int, QProcess::ExitStatus){ void GUI::cleanTempPreviewFile(int, QProcess::ExitStatus){
QFile::remove(QDir::tempPath()+QDir::separator()+"qBT_preview.tmp"); if(!QFile::remove(QDir::tempPath()+QDir::separator()+"qBT_preview.tmp")){
std::cerr << "Couldn't remove temporary file: " << (const char*)(QDir::tempPath()+QDir::separator()+"qBT_preview.tmp").toUtf8() << "\n";
}
} }
void GUI::displayDLListMenu(const QPoint& pos){ void GUI::displayDLListMenu(const QPoint& pos){
@ -457,28 +461,37 @@ void GUI::displayDLListMenu(const QPoint& pos){
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes();
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
QString previewProgram = settings.value("Options/Misc/PreviewProgram", QString()).toString(); QString previewProgram = settings.value("Options/Misc/PreviewProgram", QString()).toString();
bool has_pause = false, has_start = false, has_preview = false;
foreach(index, selectedIndexes){ foreach(index, selectedIndexes){
if(index.column() == NAME){ if(index.column() == NAME){
// Get the file name // Get the file name
QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString();
// Get handle and pause the torrent // Get handle and pause the torrent
torrent_handle h = BTSession->getTorrentHandle(fileHash); torrent_handle h = BTSession->getTorrentHandle(fileHash);
if(!h.is_valid()) continue;
if(h.is_paused()){ if(h.is_paused()){
myDLLlistMenu.addAction(actionStart); if(!has_start){
myDLLlistMenu.addAction(actionStart);
has_start = true;
}
}else{ }else{
myDLLlistMenu.addAction(actionPause); if(!has_pause){
myDLLlistMenu.addAction(actionPause);
has_pause = true;
}
} }
myDLLlistMenu.addAction(actionDelete); if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(fileHash) && !has_preview){
myDLLlistMenu.addAction(actionDelete_Permanently);
myDLLlistMenu.addAction(actionSet_download_limit);
myDLLlistMenu.addAction(actionSet_upload_limit);
myDLLlistMenu.addAction(actionTorrent_Properties);
if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(fileHash) && selectedIndexes.size()<=DLListModel->columnCount()){
myDLLlistMenu.addAction(actionPreview_file); myDLLlistMenu.addAction(actionPreview_file);
has_preview = true;
} }
break; if(has_pause && has_start && has_preview) break;
} }
} }
myDLLlistMenu.addAction(actionDelete);
myDLLlistMenu.addAction(actionDelete_Permanently);
myDLLlistMenu.addAction(actionSet_download_limit);
myDLLlistMenu.addAction(actionSet_upload_limit);
myDLLlistMenu.addAction(actionTorrent_Properties);
// Call menu // Call menu
// XXX: why mapToGlobal() is not enough? // XXX: why mapToGlobal() is not enough?
myDLLlistMenu.exec(mapToGlobal(pos)+QPoint(22,180)); myDLLlistMenu.exec(mapToGlobal(pos)+QPoint(22,180));
@ -809,7 +822,7 @@ void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e){
} }
// Center window // Center window
QPoint GUI::screenCenter(){ QPoint GUI::screenCenter() const{
int scrn = 0; int scrn = 0;
QWidget *w = this->topLevelWidget(); QWidget *w = this->topLevelWidget();

4
src/GUI.h

@ -130,7 +130,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void displayUpTab(); void displayUpTab();
void displaySearchTab(); void displaySearchTab();
void displayRSSTab(); void displayRSSTab();
void handleDownloadFromUrlFailure(QString, QString); void handleDownloadFromUrlFailure(QString, QString) const;
// Torrent actions // Torrent actions
void showProperties(const QModelIndex &index); void showProperties(const QModelIndex &index);
void on_actionTorrent_Properties_triggered(); void on_actionTorrent_Properties_triggered();
@ -188,7 +188,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
// Methods // Methods
int getRowFromHash(QString hash) const; int getRowFromHash(QString hash) const;
unsigned int getCurrentTabIndex() const; unsigned int getCurrentTabIndex() const;
QPoint screenCenter(); QPoint screenCenter() const;
}; };
#endif #endif

Loading…
Cancel
Save