From 8ec1621334b8a952160f9af1330f0f38c857b319 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 5 Jun 2010 18:59:05 +0000 Subject: [PATCH] Merge msvc fixes from stable branch --- src/bittorrent.cpp | 6 +++--- src/eventmanager.cpp | 14 +++++++++++--- src/misc.cpp | 32 +++++++++++++++++++++++++++++++- src/misc.h | 5 +++++ src/peerlistwidget.cpp | 10 ++++------ src/preferences.h | 11 +++++++---- src/propertieswidget.cpp | 10 ++++------ src/rss.h | 2 +- src/rss_imp.cpp | 9 ++++----- src/torrentadditiondlg.h | 9 ++++----- src/torrentpersistentdata.h | 10 +++++----- src/trackerlist.cpp | 10 ++++------ src/transferlistwidget.cpp | 10 ++++------ 13 files changed, 87 insertions(+), 51 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 939138e56..94630e684 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -288,13 +288,13 @@ void Bittorrent::configureSession() { startTorrentsInPause(Preferences::addTorrentsInPause()); // * Scan dirs const QStringList &scan_dirs = Preferences::getScanDirs(); - QVariantList downloadInDirList = Preferences::getDownloadInScanDirs(); + QList downloadInDirList = Preferences::getDownloadInScanDirs(); while(scan_dirs.size() > downloadInDirList.size()) { - downloadInDirList << QVariant(false); + downloadInDirList << false; } int i = 0; foreach (const QString &dir, scan_dirs) { - m_scanFolders->addPath(dir, downloadInDirList.at(i).toBool()); + m_scanFolders->addPath(dir, downloadInDirList.at(i)); ++i; } // * Export Dir diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index 85b292140..bc615a5c5 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -133,7 +133,11 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { if(m.contains("temp_path")) Preferences::setTempPath(m["temp_path"].toString()); if(m.contains("scan_dirs") && m.contains("download_in_scan_dirs")) { - QVariantList download_at_path = m["download_in_scan_dirs"].toList(); + QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList(); + QList download_at_path; + foreach(QVariant var, download_at_path_tmp) { + download_at_path << var.toBool(); + } QStringList old_folders = Preferences::getScanDirs(); QStringList new_folders = m["scan_dirs"].toStringList(); if(download_at_path.size() == new_folders.size()) { @@ -149,7 +153,7 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { foreach(const QString &new_folder, new_folders) { // Update new folders if(!old_folders.contains(new_folder)) { - BTSession->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i).toBool()); + BTSession->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i)); } ++i; } @@ -258,7 +262,11 @@ QVariantMap EventManager::getGlobalPreferences() const { data["temp_path_enabled"] = Preferences::isTempPathEnabled(); data["temp_path"] = Preferences::getTempPath(); data["scan_dirs"] = Preferences::getScanDirs(); - data["download_in_scan_dirs"] = Preferences::getDownloadInScanDirs(); + QVariantList var_list; + foreach(bool b, Preferences::getDownloadInScanDirs()) { + var_list << b; + } + data["download_in_scan_dirs"] = var_list; data["export_dir_enabled"] = Preferences::isTorrentExportEnabled(); data["export_dir"] = Preferences::getExportDir(); data["preallocate_all"] = Preferences::preAllocateAllFiles(); diff --git a/src/misc.cpp b/src/misc.cpp index 48753d344..24c95eb5d 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -75,7 +75,7 @@ QString misc::QDesktopServicesDataLocation() { if (!QCoreApplication::applicationName().isEmpty()) result = result + QLatin1String("\\") + qApp->applicationName(); if(!result.endsWith("\\")) - result += "\\"; + result += "\\"; return result; #else #ifdef Q_WS_MAC @@ -544,3 +544,33 @@ QString misc::userFriendlyDuration(qlonglong seconds) { } return QString::fromUtf8("∞"); } + +QStringList misc::toStringList(const QList &l) { + QStringList ret; + foreach(const bool &b, l) { + if(b) + ret << "1"; + else + ret << "0"; + } + return ret; +} + +QList misc::intListfromStringList(const QStringList &l) { + QList ret; + foreach(const QString &s, l) { + ret << s.toInt(); + } + return ret; +} + +QList misc::boolListfromStringList(const QStringList &l) { + QList ret; + foreach(const QString &s, l) { + if(s == "1") + ret << true; + else + ret << false; + } + return ret; +} diff --git a/src/misc.h b/src/misc.h index 8e5ed7f5b..649f8d9c3 100644 --- a/src/misc.h +++ b/src/misc.h @@ -121,6 +121,11 @@ public: // Take a number of seconds and return an user-friendly // time duration like "1d 2h 10m". static QString userFriendlyDuration(qlonglong seconds); + + // Convert functions + static QStringList toStringList(const QList &l); + static QList intListfromStringList(const QStringList &l); + static QList boolListfromStringList(const QStringList &l); }; // Trick to get a portable sleep() function diff --git a/src/peerlistwidget.cpp b/src/peerlistwidget.cpp index fead64b9d..bdfaf3490 100644 --- a/src/peerlistwidget.cpp +++ b/src/peerlistwidget.cpp @@ -44,8 +44,6 @@ #include #include -Q_DECLARE_METATYPE(QList) - PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), display_flags(false) { // Visual settings setRootIsDecorated(false); @@ -246,7 +244,7 @@ void PeerListWidget::clear() { void PeerListWidget::loadSettings() { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QList contentColsWidths = settings.value(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), QVariantList()).value >(); + QList contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth")).toStringList()); if(!contentColsWidths.empty()) { for(int i=0; i contentColsWidths; + QStringList contentColsWidths; for(int i=0; icolumnCount(); ++i) { - contentColsWidths.append(columnWidth(i)); + contentColsWidths << QString::number(columnWidth(i)); } - settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), QVariant::fromValue >(contentColsWidths)); + settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), contentColsWidths); // Save sorted column Qt::SortOrder sortOrder = header()->sortIndicatorOrder(); QString sortOrderLetter; diff --git a/src/preferences.h b/src/preferences.h index aff859b89..bf5bc686b 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -36,6 +36,7 @@ #include #include #include +#include #ifndef DISABLE_GUI #include @@ -47,6 +48,8 @@ #include #endif +#include "misc.h" + #define QBT_REALM "Web UI Access" enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN }; @@ -223,14 +226,14 @@ public: settings.setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), dirs); } - static QVariantList getDownloadInScanDirs() { + static QList getDownloadInScanDirs() { QSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs"), QVariantList()).toList(); + return misc::boolListfromStringList(settings.value(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs")).toStringList()); } - static void setDownloadInScanDirs(const QVariantList &list) { + static void setDownloadInScanDirs(const QList &list) { QSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs"), list); + settings.setValue(QString::fromUtf8("Preferences/Downloads/DownloadInScanDirs"), misc::toStringList(list)); } static bool isTorrentExportEnabled() { diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index bb3e36a46..83f72b53f 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -52,8 +52,6 @@ #include "downloadedpiecesbar.h" #include "pieceavailabilitybar.h" -Q_DECLARE_METATYPE(QList) - #ifdef Q_WS_MAC #define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px; margin-left: 8px; margin-right: 8px;}" #define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 8px; margin-right: 8px;}" @@ -267,7 +265,7 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) { void PropertiesWidget::readSettings() { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QList contentColsWidths = settings.value(QString::fromUtf8("TorrentProperties/filesColsWidth"), QVariantList()).value >(); + QList contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/filesColsWidth")).toStringList()); if(contentColsWidths.empty()) { filesList->header()->resizeSection(0, 300); } else { @@ -294,11 +292,11 @@ void PropertiesWidget::readSettings() { void PropertiesWidget::saveSettings() { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); settings.setValue("TorrentProperties/Visible", state==VISIBLE); - QList contentColsWidths; + QStringList contentColsWidths; for(int i=0; icolumnCount(); ++i) { - contentColsWidths.append(filesList->columnWidth(i)); + contentColsWidths << QString::number(filesList->columnWidth(i)); } - settings.setValue(QString::fromUtf8("TorrentProperties/filesColsWidth"), QVariant::fromValue >(contentColsWidths)); + settings.setValue(QString::fromUtf8("TorrentProperties/filesColsWidth"), contentColsWidths); // Splitter sizes QSplitter *hSplitter = static_cast(parentWidget()); QList sizes; diff --git a/src/rss.h b/src/rss.h index f8be682c0..459b5c20d 100644 --- a/src/rss.h +++ b/src/rss.h @@ -345,7 +345,7 @@ public: return item; } - static RssItem* fromHash(RssStream* parent, QHash h) { + static RssItem* fromHash(RssStream* parent, const QHash &h) { return new RssItem(parent, h.value("id", "").toString(), h["title"].toString(), h["torrent_url"].toString(), h["news_link"].toString(), h["description"].toString(), h["date"].toDateTime(), h["author"].toString(), h["read"].toBool()); } diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index 633795c57..92ac4c4a3 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -251,13 +251,12 @@ void RSSImp::deleteSelectedItems() { void RSSImp::loadFoldersOpenState() { QSettings settings("qBittorrent", "qBittorrent"); settings.beginGroup("Rss"); - QVariantList open_folders = settings.value("open_folders", QVariantList()).toList(); + QStringList open_folders = settings.value("open_folders", QStringList()).toStringList(); settings.endGroup(); - foreach(QVariant var_path, open_folders) { - QStringList path = var_path.toString().split("\\"); + foreach(QString var_path, open_folders) { + QStringList path = var_path.split("\\"); QTreeWidgetItem *parent = 0; foreach(QString name, path) { - QList children; int nbChildren = 0; if(parent) nbChildren = parent->childCount(); @@ -281,7 +280,7 @@ void RSSImp::loadFoldersOpenState() { } void RSSImp::saveFoldersOpenState() { - QVariantList open_folders; + QStringList open_folders; QList items = listStreams->getAllOpenFolders(); foreach(QTreeWidgetItem* item, items) { QString path = listStreams->getItemPath(item).join("\\"); diff --git a/src/torrentadditiondlg.h b/src/torrentadditiondlg.h index 714bb6477..5e8e168b3 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -56,7 +56,6 @@ #include "transferlistwidget.h" using namespace libtorrent; -Q_DECLARE_METATYPE(QList) class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ Q_OBJECT @@ -126,7 +125,7 @@ public: resize(settings.value(QString::fromUtf8("TorrentAdditionDlg/size"), size()).toSize()); move(settings.value(QString::fromUtf8("TorrentAdditionDlg/pos"), misc::screenCenter(this)).toPoint()); // Restore column width - const QList &contentColsWidths = settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth")).value >(); + const QList &contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth")).toStringList()); if(contentColsWidths.empty()) { torrentContentList->header()->resizeSection(0, 200); } else { @@ -139,12 +138,12 @@ public: void saveSettings() { if(is_magnet) return; QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QList contentColsWidths; + QStringList contentColsWidths; // -1 because we hid PROGRESS column for(int i=0; icolumnCount()-1; ++i) { - contentColsWidths.append(torrentContentList->columnWidth(i)); + contentColsWidths << QString::number(torrentContentList->columnWidth(i)); } - settings.setValue(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth"), QVariant::fromValue >(contentColsWidths)); + settings.setValue(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth"), contentColsWidths); settings.setValue("TorrentAdditionDlg/size", size()); settings.setValue("TorrentAdditionDlg/pos", pos()); } diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index 3f9d162f4..44d1b2184 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -69,9 +69,9 @@ public: QHash all_data = settings.value("torrents-tmp", QHash()).toHash(); QHash data = all_data[hash].toHash(); std::vector::const_iterator pp_it = pp.begin(); - QVariantList pieces_priority; + QStringList pieces_priority; while(pp_it != pp.end()) { - pieces_priority << *pp_it; + pieces_priority << QString::number(*pp_it); pp_it++; } data["files_priority"] = pieces_priority; @@ -179,9 +179,9 @@ public: QHash data = all_data[hash].toHash(); std::vector fp; if(data.contains("files_priority")) { - QVariantList list_var = data["files_priority"].toList(); - foreach(const QVariant& var, list_var) { - fp.push_back(var.toInt()); + QList list_var = misc::intListfromStringList(data["files_priority"].toStringList()); + foreach(int var, list_var) { + fp.push_back(var); } } return fp; diff --git a/src/trackerlist.cpp b/src/trackerlist.cpp index d0343d82b..29d8c3bb0 100644 --- a/src/trackerlist.cpp +++ b/src/trackerlist.cpp @@ -42,8 +42,6 @@ #include "misc.h" #include "bittorrent.h" -Q_DECLARE_METATYPE(QList) - TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) { // Graphical settings setRootIsDecorated(false); @@ -363,7 +361,7 @@ void TrackerList::showTrackerListMenu(QPoint) { void TrackerList::loadSettings() { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QList contentColsWidths = settings.value(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth")).value >(); + QList contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth")).toStringList()); if(!contentColsWidths.empty()) { for(int i=0; i contentColsWidths; + QStringList contentColsWidths; for(int i=0; i >(contentColsWidths)); + settings.setValue(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth"), contentColsWidths); } diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index a03172cf7..27f71b1c1 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -52,8 +52,6 @@ #include #include -Q_DECLARE_METATYPE(QList) - TransferListWidget::TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent *_BTSession): QTreeView(parent), BTSession(_BTSession), main_window(main_window) { QSettings settings("qBittorrent", "qBittorrent"); @@ -1263,11 +1261,11 @@ void TransferListWidget::saveColWidthList() { } } settings.setValue(QString::fromUtf8("TransferListColsWidth"), new_width_list.join(QString::fromUtf8(" "))); - QList visualIndexes; + QStringList visualIndexes; for(int i=0; ivisualIndex(i)); + visualIndexes << QString::number(header()->visualIndex(i)); } - settings.setValue(QString::fromUtf8("TransferListVisualIndexes"), QVariant::fromValue< QList >(visualIndexes)); + settings.setValue(QString::fromUtf8("TransferListVisualIndexes"), visualIndexes); qDebug("Download list columns width saved"); } @@ -1287,7 +1285,7 @@ bool TransferListWidget::loadColWidthList() { for(unsigned int i=0; iresizeSection(i, width_list.at(i).toInt()); } - const QList visualIndexes = settings.value(QString::fromUtf8("TransferListVisualIndexes")).value >(); + const QList visualIndexes = misc::intListfromStringList(settings.value(QString::fromUtf8("TransferListVisualIndexes")).toStringList()); if(visualIndexes.size() != listModel->columnCount()-1) { qDebug("Corrupted values for transfer list columns indexes"); return false;