From 0c795cce28a7a6a88c7dc90162589303d57f2a3f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 14 Nov 2006 21:36:29 +0000 Subject: [PATCH] - Cleaned up the way columns width are remembered --- src/GUI.cpp | 88 +++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 60 deletions(-) diff --git a/src/GUI.cpp b/src/GUI.cpp index 4b2b8fda0..f9ed28a8c 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -809,94 +809,62 @@ void GUI::saveCheckedSearchEngines(int) const{ // (download list) void GUI::saveColWidthDLList() const{ qDebug("Saving columns width in download list"); - QFile lastDLListWidth(misc::qBittorrentPath()+"lastDLListWidth.txt"); - // delete old file - lastDLListWidth.remove(); + QSettings settings("qBittorrent", "qBittorrent"); QStringList width_list; for(int i=0; icolumnCount(); ++i){ width_list << QString(misc::toString(downloadList->columnWidth(i)).c_str()); } - if(lastDLListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ - lastDLListWidth.write(width_list.join(" ").toAscii()); - lastDLListWidth.close(); - qDebug("Columns width saved"); - }else{ - std::cerr << "Error: Could not save last columns width in download list\n"; - } + settings.setValue("DownloadListColsWidth", width_list.join(" ")); + qDebug("Download list columns width saved"); } // Load columns width in a file that were saved previously // (download list) bool GUI::loadColWidthDLList(){ - qDebug("Loading colums width in download list"); - QFile lastDLListWidth(misc::qBittorrentPath()+"lastDLListWidth.txt"); - if(lastDLListWidth.exists()){ - if(lastDLListWidth.open(QIODevice::ReadOnly | QIODevice::Text)){ - QByteArray line = lastDLListWidth.readLine(); - lastDLListWidth.close(); - line.chop(1); - QStringList width_list = QString(line).split(' '); - if(width_list.size() != DLListModel-> columnCount()){ - return false; - } - for(int i=0; icolumnCount()) + return false; + for(int i=0; iheader()->resizeSection(i, width_list.at(i).toInt()); - } - qDebug("Loaded columns width in download list"); - return true; - }else{ - std::cerr << "Error: Could not load last columns width for download list\n"; - return false; - } } - return false; + qDebug("Download list columns width loaded"); + return true; } // Save columns width in a file to remember them // (download list) void GUI::saveColWidthSearchList() const{ qDebug("Saving columns width in search list"); - QFile lastSearchListWidth(misc::qBittorrentPath()+"lastSearchListWidth.txt"); - // delete old file - lastSearchListWidth.remove(); + QSettings settings("qBittorrent", "qBittorrent"); QStringList width_list; for(int i=0; icolumnCount(); ++i){ width_list << QString(misc::toString(resultsBrowser->columnWidth(i)).c_str()); } - if(lastSearchListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ - lastSearchListWidth.write(width_list.join(" ").toAscii()); - lastSearchListWidth.close(); - qDebug("Columns width saved in search list"); - }else{ - std::cerr << "Error: Could not save last columns width in search results list\n"; - } + settings.setValue("SearchListColsWidth", width_list.join(" ")); + qDebug("Search list columns width saved"); } // Load columns width in a file that were saved previously // (search list) bool GUI::loadColWidthSearchList(){ - qDebug("Loading column width in search list"); - QFile lastSearchListWidth(misc::qBittorrentPath()+"lastSearchListWidth.txt"); - if(lastSearchListWidth.exists()){ - if(lastSearchListWidth.open(QIODevice::ReadOnly | QIODevice::Text)){ - QByteArray line = lastSearchListWidth.readLine(); - lastSearchListWidth.close(); - line.chop(1); - QStringList width_list = QString(line).split(' '); - if(width_list.size() != SearchListModel-> columnCount()){ - return false; - } - for(int i=0; icolumnCount()) + return false; + for(int i=0; iheader()->resizeSection(i, width_list.at(i).toInt()); - } - qDebug("Columns width loaded in search list"); - return true; - }else{ - std::cerr << "Error: Could not load last columns width for search results list\n"; - return false; - } } - return false; + qDebug("Search list columns width loaded"); + return true; } // load last checked search engines from a file