Browse Source

- Cleaned up the way columns width are remembered

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
0c795cce28
  1. 76
      src/GUI.cpp

76
src/GUI.cpp

@ -809,94 +809,62 @@ void GUI::saveCheckedSearchEngines(int) const{
// (download list) // (download list)
void GUI::saveColWidthDLList() const{ void GUI::saveColWidthDLList() const{
qDebug("Saving columns width in download list"); qDebug("Saving columns width in download list");
QFile lastDLListWidth(misc::qBittorrentPath()+"lastDLListWidth.txt"); QSettings settings("qBittorrent", "qBittorrent");
// delete old file
lastDLListWidth.remove();
QStringList width_list; QStringList width_list;
for(int i=0; i<DLListModel->columnCount(); ++i){ for(int i=0; i<DLListModel->columnCount(); ++i){
width_list << QString(misc::toString(downloadList->columnWidth(i)).c_str()); width_list << QString(misc::toString(downloadList->columnWidth(i)).c_str());
} }
if(lastDLListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ settings.setValue("DownloadListColsWidth", width_list.join(" "));
lastDLListWidth.write(width_list.join(" ").toAscii()); qDebug("Download list columns width saved");
lastDLListWidth.close();
qDebug("Columns width saved");
}else{
std::cerr << "Error: Could not save last columns width in download list\n";
}
} }
// Load columns width in a file that were saved previously // Load columns width in a file that were saved previously
// (download list) // (download list)
bool GUI::loadColWidthDLList(){ bool GUI::loadColWidthDLList(){
qDebug("Loading colums width in download list"); qDebug("Loading columns width for download list");
QFile lastDLListWidth(misc::qBittorrentPath()+"lastDLListWidth.txt"); QSettings settings("qBittorrent", "qBittorrent");
if(lastDLListWidth.exists()){ QString line = settings.value("DownloadListColsWidth", QString()).toString();
if(lastDLListWidth.open(QIODevice::ReadOnly | QIODevice::Text)){ if(line.isEmpty())
QByteArray line = lastDLListWidth.readLine(); return false;
lastDLListWidth.close(); QStringList width_list = line.split(' ');
line.chop(1); if(width_list.size() != DLListModel->columnCount())
QStringList width_list = QString(line).split(' ');
if(width_list.size() != DLListModel-> columnCount()){
return false; return false;
}
for(int i=0; i<width_list.size(); ++i){ for(int i=0; i<width_list.size(); ++i){
downloadList->header()->resizeSection(i, width_list.at(i).toInt()); downloadList->header()->resizeSection(i, width_list.at(i).toInt());
} }
qDebug("Loaded columns width in download list"); qDebug("Download list columns width loaded");
return true; return true;
}else{
std::cerr << "Error: Could not load last columns width for download list\n";
return false;
}
}
return false;
} }
// Save columns width in a file to remember them // Save columns width in a file to remember them
// (download list) // (download list)
void GUI::saveColWidthSearchList() const{ void GUI::saveColWidthSearchList() const{
qDebug("Saving columns width in search list"); qDebug("Saving columns width in search list");
QFile lastSearchListWidth(misc::qBittorrentPath()+"lastSearchListWidth.txt"); QSettings settings("qBittorrent", "qBittorrent");
// delete old file
lastSearchListWidth.remove();
QStringList width_list; QStringList width_list;
for(int i=0; i<SearchListModel->columnCount(); ++i){ for(int i=0; i<SearchListModel->columnCount(); ++i){
width_list << QString(misc::toString(resultsBrowser->columnWidth(i)).c_str()); width_list << QString(misc::toString(resultsBrowser->columnWidth(i)).c_str());
} }
if(lastSearchListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ settings.setValue("SearchListColsWidth", width_list.join(" "));
lastSearchListWidth.write(width_list.join(" ").toAscii()); qDebug("Search list columns width saved");
lastSearchListWidth.close();
qDebug("Columns width saved in search list");
}else{
std::cerr << "Error: Could not save last columns width in search results list\n";
}
} }
// Load columns width in a file that were saved previously // Load columns width in a file that were saved previously
// (search list) // (search list)
bool GUI::loadColWidthSearchList(){ bool GUI::loadColWidthSearchList(){
qDebug("Loading column width in search list"); qDebug("Loading columns width for search list");
QFile lastSearchListWidth(misc::qBittorrentPath()+"lastSearchListWidth.txt"); QSettings settings("qBittorrent", "qBittorrent");
if(lastSearchListWidth.exists()){ QString line = settings.value("SearchListColsWidth", QString()).toString();
if(lastSearchListWidth.open(QIODevice::ReadOnly | QIODevice::Text)){ if(line.isEmpty())
QByteArray line = lastSearchListWidth.readLine(); return false;
lastSearchListWidth.close(); QStringList width_list = line.split(' ');
line.chop(1); if(width_list.size() != SearchListModel->columnCount())
QStringList width_list = QString(line).split(' ');
if(width_list.size() != SearchListModel-> columnCount()){
return false; return false;
}
for(int i=0; i<width_list.size(); ++i){ for(int i=0; i<width_list.size(); ++i){
resultsBrowser->header()->resizeSection(i, width_list.at(i).toInt()); resultsBrowser->header()->resizeSection(i, width_list.at(i).toInt());
} }
qDebug("Columns width loaded in search list"); qDebug("Search list columns width loaded");
return true; return true;
}else{
std::cerr << "Error: Could not load last columns width for search results list\n";
return false;
}
}
return false;
} }
// load last checked search engines from a file // load last checked search engines from a file

Loading…
Cancel
Save