Browse Source

- Optimizing

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
85463e3910
  1. 47
      src/properties_imp.cpp
  2. 12
      src/torrentAddition.h

47
src/properties_imp.cpp

@ -281,11 +281,10 @@ void properties::updatePriorities(QStandardItem *item) {
} }
void properties::loadWebSeeds(){ void properties::loadWebSeeds(){
QString url_seed;
// Clear url seeds list // Clear url seeds list
listWebSeeds->clear(); listWebSeeds->clear();
// Add manually added url seeds // Add manually added url seeds
foreach(url_seed, urlSeeds){ foreach(const QString &url_seed, urlSeeds){
listWebSeeds->addItem(url_seed); listWebSeeds->addItem(url_seed);
qDebug("Added custom url seed to list: %s", url_seed.toUtf8().data()); qDebug("Added custom url seed to list: %s", url_seed.toUtf8().data());
} }
@ -372,8 +371,7 @@ void properties::displayFilesListMenu(const QPoint& pos){
void properties::ignoreSelection(){ void properties::ignoreSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
if(PropListModel->data(index) != QVariant(IGNORED)){ if(PropListModel->data(index) != QVariant(IGNORED)){
PropListModel->setData(index, QVariant(IGNORED)); PropListModel->setData(index, QVariant(IGNORED));
@ -388,8 +386,7 @@ void properties::ignoreSelection(){
void properties::normalSelection(){ void properties::normalSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
if(PropListModel->data(index) != QVariant(NORMAL)){ if(PropListModel->data(index) != QVariant(NORMAL)){
PropListModel->setData(index, QVariant(NORMAL)); PropListModel->setData(index, QVariant(NORMAL));
@ -404,8 +401,7 @@ void properties::normalSelection(){
void properties::highSelection(){ void properties::highSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
if(PropListModel->data(index) != QVariant(HIGH)){ if(PropListModel->data(index) != QVariant(HIGH)){
PropListModel->setData(index, QVariant(HIGH)); PropListModel->setData(index, QVariant(HIGH));
@ -420,8 +416,7 @@ void properties::highSelection(){
void properties::maximumSelection(){ void properties::maximumSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
if(PropListModel->data(index) != QVariant(MAXIMUM)){ if(PropListModel->data(index) != QVariant(MAXIMUM)){
PropListModel->setData(index, QVariant(MAXIMUM)); PropListModel->setData(index, QVariant(MAXIMUM));
@ -492,7 +487,7 @@ void properties::askForTracker(){
void properties::addTrackerList(QStringList myTrackers) { void properties::addTrackerList(QStringList myTrackers) {
// Add the trackers to the list // Add the trackers to the list
std::vector<announce_entry> trackers = h.trackers(); std::vector<announce_entry> trackers = h.trackers();
foreach(QString tracker, myTrackers) { foreach(const QString& tracker, myTrackers) {
announce_entry new_tracker(misc::toString(tracker.trimmed().toUtf8().data())); announce_entry new_tracker(misc::toString(tracker.trimmed().toUtf8().data()));
new_tracker.tier = 0; // Will be fixed a bit later new_tracker.tier = 0; // Will be fixed a bit later
trackers.push_back(new_tracker); trackers.push_back(new_tracker);
@ -506,11 +501,9 @@ void properties::addTrackerList(QStringList myTrackers) {
} }
void properties::deleteSelectedUrlSeeds(){ void properties::deleteSelectedUrlSeeds(){
QList<QListWidgetItem *> selectedItems; QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
selectedItems = listWebSeeds->selectedItems();
QListWidgetItem *item;
bool change = false; bool change = false;
foreach(item, selectedItems){ foreach(QListWidgetItem *item, selectedItems){
QString url_seed = item->text(); QString url_seed = item->text();
int index = urlSeeds.indexOf(url_seed); int index = urlSeeds.indexOf(url_seed);
Q_ASSERT(index != -1); Q_ASSERT(index != -1);
@ -530,7 +523,6 @@ void properties::deleteSelectedTrackers(){
QList<QListWidgetItem *> selectedItems = trackersURLS->selectedItems(); QList<QListWidgetItem *> selectedItems = trackersURLS->selectedItems();
if(!selectedItems.size()) return; if(!selectedItems.size()) return;
std::vector<announce_entry> trackers = h.trackers(); std::vector<announce_entry> trackers = h.trackers();
QListWidgetItem *item;
unsigned int nbTrackers = trackers.size(); unsigned int nbTrackers = trackers.size();
if(nbTrackers == (unsigned int) selectedItems.size()){ if(nbTrackers == (unsigned int) selectedItems.size()){
QMessageBox::warning(this, tr("qBittorrent"), QMessageBox::warning(this, tr("qBittorrent"),
@ -538,7 +530,7 @@ void properties::deleteSelectedTrackers(){
QMessageBox::Ok); QMessageBox::Ok);
return; return;
} }
foreach(item, selectedItems){ foreach(QListWidgetItem *item, selectedItems){
QString url = item->text(); QString url = item->text();
for(unsigned int i=0; i<nbTrackers; ++i){ for(unsigned int i=0; i<nbTrackers; ++i){
if(misc::toQString(trackers.at(i).url) == url){ if(misc::toQString(trackers.at(i).url) == url){
@ -557,12 +549,10 @@ void properties::deleteSelectedTrackers(){
void properties::riseSelectedTracker(){ void properties::riseSelectedTracker(){
unsigned int i = 0; unsigned int i = 0;
std::vector<announce_entry> trackers = h.trackers(); std::vector<announce_entry> trackers = h.trackers();
QList<QListWidgetItem *> selectedItems; QList<QListWidgetItem *> selectedItems = trackersURLS->selectedItems();
selectedItems = trackersURLS->selectedItems();
QListWidgetItem *item;
bool change = false; bool change = false;
unsigned int nbTrackers = trackers.size(); unsigned int nbTrackers = trackers.size();
foreach(item, selectedItems){ foreach(QListWidgetItem *item, selectedItems){
QString url = item->text(); QString url = item->text();
for(i=0; i<nbTrackers; ++i){ for(i=0; i<nbTrackers; ++i){
if(misc::toQString(trackers.at(i).url) == url){ if(misc::toQString(trackers.at(i).url) == url){
@ -592,12 +582,10 @@ void properties::riseSelectedTracker(){
void properties::lowerSelectedTracker(){ void properties::lowerSelectedTracker(){
unsigned int i = 0; unsigned int i = 0;
std::vector<announce_entry> trackers = h.trackers(); std::vector<announce_entry> trackers = h.trackers();
QList<QListWidgetItem *> selectedItems; QList<QListWidgetItem *> selectedItems = trackersURLS->selectedItems();
selectedItems = trackersURLS->selectedItems();
QListWidgetItem *item;
bool change = false; bool change = false;
unsigned int nbTrackers = trackers.size(); unsigned int nbTrackers = trackers.size();
foreach(item, selectedItems){ foreach(QListWidgetItem *item, selectedItems){
QString url = item->text(); QString url = item->text();
for(i=0; i<nbTrackers; ++i){ for(i=0; i<nbTrackers; ++i){
if(misc::toQString(trackers.at(i).url) == url){ if(misc::toQString(trackers.at(i).url) == url){
@ -718,16 +706,14 @@ void properties::loadWebSeedsFromFile(){
urlseeds_file.close(); urlseeds_file.close();
QList<QByteArray> url_seeds = urlseeds_lines.split('\n'); QList<QByteArray> url_seeds = urlseeds_lines.split('\n');
urlSeeds.clear(); urlSeeds.clear();
QByteArray url_seed; foreach(const QByteArray &url_seed, url_seeds){
foreach(url_seed, url_seeds){
if(!url_seed.isEmpty()) if(!url_seed.isEmpty())
urlSeeds << url_seed; urlSeeds << url_seed;
} }
// Load the hard-coded url seeds // Load the hard-coded url seeds
QStringList hc_seeds = h.url_seeds(); QStringList hc_seeds = h.url_seeds();
QString hc_seed;
// Add hard coded url seeds // Add hard coded url seeds
foreach(hc_seed, hc_seeds){ foreach(const QString &hc_seed, hc_seeds){
if(urlSeeds.indexOf(hc_seed) == -1){ if(urlSeeds.indexOf(hc_seed) == -1){
urlSeeds << hc_seed; urlSeeds << hc_seed;
} }
@ -740,8 +726,7 @@ void properties::saveWebSeeds(){
std::cerr << "Error: Could not save url seeds\n"; std::cerr << "Error: Could not save url seeds\n";
return; return;
} }
QString url_seed; foreach(const QString &url_seed, urlSeeds){
foreach(url_seed, urlSeeds){
urlseeds_file.write((url_seed+"\n").toUtf8()); urlseeds_file.write((url_seed+"\n").toUtf8());
} }
urlseeds_file.close(); urlseeds_file.close();

12
src/torrentAddition.h

@ -299,8 +299,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
void ignoreSelection(){ void ignoreSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(IGNORED)); PropListModel->setData(index, QVariant(IGNORED));
} }
@ -312,8 +311,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
void normalSelection(){ void normalSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(NORMAL)); PropListModel->setData(index, QVariant(NORMAL));
} }
@ -325,8 +323,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
void highSelection(){ void highSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(HIGH)); PropListModel->setData(index, QVariant(HIGH));
} }
@ -338,8 +335,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
void maximumSelection(){ void maximumSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
QModelIndex index; foreach(const QModelIndex &index, selectedIndexes){
foreach(index, selectedIndexes){
if(index.column() == PRIORITY){ if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(MAXIMUM)); PropListModel->setData(index, QVariant(MAXIMUM));
} }

Loading…
Cancel
Save