mainwindow: save/load complete window geometry and state

- Replaces the use of position and size 2d vectors when saving qt
  application settings to the registry with geometry and state
  byte arrays which includes information about the window's screen
  number and fixes a bug which prevents the main window from ever
  starting correctly maximized due to the disregarded taskbar
  offset.

Change-Id: Iaa15f075970675e85ffcdb26da962a19a1914252
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 531d9c3..ed7b5aa 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -83,17 +83,7 @@
     }
 #endif
 
-    QSettings settings;
-    QVariant size = settings.value(SettingsKey::savedSize);
-    QVariant posV = settings.value(SettingsKey::savedPos);
-    if (size.isValid() && posV.isValid()) {
-        resize(size.toSize());
-        auto screenSize = QApplication::desktop()->screenGeometry();
-        auto pos = posV.toPoint();
-        if (pos.rx() < screenSize.width() && pos.ry() < screenSize.height())
-            move(pos);
-    } else
-        resize(800, 600);
+    readSettingsFromRegistry();
 
     win_sparkle_set_appcast_url("http://dl.ring.cx/windows/winsparkle-ring.xml");
     win_sparkle_set_app_details(L"Savoir-faire Linux", L"Ring", QString(NIGHTLY_VERSION).toStdWString().c_str());
@@ -111,9 +101,6 @@
 
     setContextMenuPolicy(Qt::NoContextMenu);
 
-    if (not settings.contains(SettingsKey::enableNotifications)) {
-        settings.setValue(SettingsKey::enableNotifications, true);
-    }
     connect(&GlobalSystemTray::instance(), SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
 
     connect(&netManager_, &QNetworkConfigurationManager::onlineStateChanged, [=](bool online) {
@@ -227,7 +214,19 @@
         this->hide();
         event->ignore();
     } else {
-        settings.setValue(SettingsKey::savedSize, size());
-        settings.setValue(SettingsKey::savedPos, pos());
+        settings.setValue(SettingsKey::geometry, saveGeometry());

+        settings.setValue(SettingsKey::windowState, saveState());
     }
+    QMainWindow::closeEvent(event);
 }
+
+void

+MainWindow::readSettingsFromRegistry()

+{

+    QSettings settings;

+    restoreGeometry(settings.value(SettingsKey::geometry).toByteArray());

+    restoreState(settings.value(SettingsKey::windowState).toByteArray());

+    if (not settings.contains(SettingsKey::enableNotifications)) {
+        settings.setValue(SettingsKey::enableNotifications, true);
+    }

+}
\ No newline at end of file