mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 12:34:19 +00:00
- Remember mainwindow position during last exec
This commit is contained in:
parent
9f721afe03
commit
719ac93024
74
src/GUI.cpp
74
src/GUI.cpp
@ -32,6 +32,7 @@
|
||||
#include <QModelIndex>
|
||||
#include <QHeaderView>
|
||||
#include <QScrollBar>
|
||||
#include <QSettings>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
@ -59,7 +60,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
|
||||
setupUi(this);
|
||||
setWindowTitle(tr("qBittorrent ")+VERSION);
|
||||
QCoreApplication::setApplicationName("qBittorrent");
|
||||
loadWindowSize();
|
||||
readSettings();
|
||||
s = new session(fingerprint("qB", 0, 7, 0, 0));
|
||||
//s = new session(fingerprint("AZ", 2, 5, 0, 0)); //Azureus fingerprint
|
||||
// Setting icons
|
||||
@ -165,8 +166,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
|
||||
refresher = new QTimer(this);
|
||||
connect(refresher, SIGNAL(timeout()), this, SLOT(updateDlList()));
|
||||
refresher->start(2000);
|
||||
// Center window
|
||||
centerWindow();
|
||||
// Tray icon Menu
|
||||
myTrayIconMenu = new QMenu(this);
|
||||
myTrayIconMenu->addAction(actionOpen);
|
||||
@ -267,6 +266,22 @@ GUI::~GUI(){
|
||||
delete s;
|
||||
}
|
||||
|
||||
void GUI::writeSettings() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
settings.beginGroup("MainWindow");
|
||||
settings.setValue("size", size());
|
||||
settings.setValue("pos", pos());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void GUI::readSettings() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
settings.beginGroup("MainWindow");
|
||||
resize(settings.value("size", size()).toSize());
|
||||
move(settings.value("pos", screenCenter()).toPoint());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
// Update Info Bar information
|
||||
void GUI::setInfoBar(const QString& info, const QString& color){
|
||||
qDebug("setInfoBar called");
|
||||
@ -710,7 +725,7 @@ void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e){
|
||||
}
|
||||
|
||||
// Center window
|
||||
void GUI::centerWindow(){
|
||||
QPoint GUI::screenCenter(){
|
||||
int scrn = 0;
|
||||
QWidget *w = this->topLevelWidget();
|
||||
|
||||
@ -722,23 +737,7 @@ void GUI::centerWindow(){
|
||||
scrn = QApplication::desktop()->screenNumber(this);
|
||||
|
||||
QRect desk(QApplication::desktop()->availableGeometry(scrn));
|
||||
|
||||
this->move((desk.width() - this->frameGeometry().width()) / 2,
|
||||
(desk.height() - this->frameGeometry().height()) / 2);
|
||||
}
|
||||
|
||||
void GUI::saveWindowSize() const{
|
||||
QFile lastWindowSize(misc::qBittorrentPath()+"lastWindowSize.txt");
|
||||
// delete old file
|
||||
lastWindowSize.remove();
|
||||
if(lastWindowSize.open(QIODevice::WriteOnly | QIODevice::Text)){
|
||||
lastWindowSize.write(QByteArray((misc::toString(this->size().width())+"\n").c_str()));
|
||||
lastWindowSize.write(QByteArray((misc::toString(this->size().height())+"\n").c_str()));
|
||||
lastWindowSize.close();
|
||||
qDebug("Saved window size");
|
||||
}else{
|
||||
std::cerr << "Error: Could not save last windows size\n";
|
||||
}
|
||||
return QPoint((desk.width() - this->frameGeometry().width()) / 2, (desk.height() - this->frameGeometry().height()) / 2);
|
||||
}
|
||||
|
||||
bool GUI::loadFilteredFiles(torrent_handle &h){
|
||||
@ -794,37 +793,6 @@ bool GUI::hasFilteredFiles(const QString& fileName){
|
||||
return false;
|
||||
}
|
||||
|
||||
void GUI::loadWindowSize(){
|
||||
qDebug("Loading window size");
|
||||
QFile lastWindowSize(misc::qBittorrentPath()+"lastWindowSize.txt");
|
||||
if(lastWindowSize.exists()){
|
||||
if(lastWindowSize.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||
int w, h;
|
||||
QByteArray line;
|
||||
// read width
|
||||
line = lastWindowSize.readLine();
|
||||
// remove '\n'
|
||||
if(line.at(line.size()-1) == '\n'){
|
||||
line.truncate(line.size()-1);
|
||||
}
|
||||
w = line.toInt();
|
||||
// read height
|
||||
line = lastWindowSize.readLine();
|
||||
// remove '\n'
|
||||
if(line.at(line.size()-1) == '\n'){
|
||||
line.truncate(line.size()-1);
|
||||
}
|
||||
h = line.toInt();
|
||||
lastWindowSize.close();
|
||||
// Apply new size
|
||||
if(w && h){
|
||||
this->resize(QSize(w, h));
|
||||
qDebug("Window size loaded");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save last checked search engines to a file
|
||||
void GUI::saveCheckedSearchEngines(int) const{
|
||||
qDebug("Saving checked window size");
|
||||
@ -1025,7 +993,7 @@ void GUI::closeEvent(QCloseEvent *e){
|
||||
}
|
||||
}
|
||||
// Save window size, columns size
|
||||
saveWindowSize();
|
||||
writeSettings();
|
||||
saveColWidthDLList();
|
||||
saveColWidthSearchList();
|
||||
// Create fast resume data
|
||||
|
@ -103,7 +103,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||
// GUI related slots
|
||||
void dropEvent(QDropEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void centerWindow();
|
||||
void toggleVisibility(QSystemTrayIcon::ActivationReason e);
|
||||
void showAbout();
|
||||
void setInfoBar(const QString& info, const QString& color="black");
|
||||
@ -118,8 +117,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||
void loadCheckedSearchEngines();
|
||||
bool loadColWidthDLList();
|
||||
bool loadColWidthSearchList();
|
||||
void saveWindowSize() const;
|
||||
void loadWindowSize();
|
||||
void sortDownloadList(int index);
|
||||
void sortDownloadListFloat(int index, Qt::SortOrder sortOrder);
|
||||
void sortDownloadListString(int index, Qt::SortOrder sortOrder);
|
||||
@ -135,6 +132,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||
void previewFile(const QString& filePath);
|
||||
void cleanTempPreviewFile(int, QProcess::ExitStatus);
|
||||
void balloonClicked();
|
||||
void writeSettings();
|
||||
void readSettings();
|
||||
// Torrent actions
|
||||
void showProperties(const QModelIndex &index);
|
||||
void propertiesSelection();
|
||||
@ -197,6 +196,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||
void updateNova() const;
|
||||
bool isFilePreviewPossible(const torrent_handle& h) const;
|
||||
QString getSavePath(QString fileName);
|
||||
QPoint screenCenter();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user