#include "awaylogview.h"
#include "action.h"
#include "actioncollection.h"
+#include "bufferhotlistfilter.h"
#include "buffermodel.h"
#include "bufferview.h"
#include "bufferviewoverlay.h"
#include "coreinfodlg.h"
#include "coreconnectdlg.h"
#include "contextmenuactionprovider.h"
+#include "debugbufferviewoverlay.h"
#include "debuglogwidget.h"
#include "debugmessagemodelfilter.h"
+#include "flatproxymodel.h"
#include "iconloader.h"
#include "inputwidget.h"
#include "inputline.h"
#include "qtuiapplication.h"
#include "qtuimessageprocessor.h"
#include "qtuisettings.h"
-#include "sessionsettings.h"
#include "settingsdlg.h"
#include "settingspagedlg.h"
#include "systemtray.h"
installEventFilter(new JumpKeyHandler(this));
QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
- connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
- connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
+ connect(app, SIGNAL(aboutToQuit()), SLOT(aboutToQuit()));
}
void MainWin::init() {
- QtUiSettings s;
- if(s.value("MainWinSize").isValid())
- resize(s.value("MainWinSize").toSize());
- else
- resize(QSize(800, 500));
-
connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
setupToolBars();
setupSystray();
setupTitleSetter();
+ setupHotList();
#ifndef HAVE_KDE
QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
QtUi::registerNotificationBackend(new KNotificationBackend(this));
#endif /* HAVE_KDE */
+ setDisconnectedState(); // Disable menus and stuff
+
// restore mainwin state
- restoreState(s.value("MainWinState").toByteArray());
+ QtUiSettings s;
+ restoreStateFromSettings(s);
// restore locked state of docks
QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
- setDisconnectedState(); // Disable menus and stuff
-
- show();
-
if(Quassel::runMode() != Quassel::Monolithic) {
showCoreConnectionDlg(true); // autoconnect if appropriate
} else {
}
MainWin::~MainWin() {
+
+}
+
+void MainWin::aboutToQuit() {
QtUiSettings s;
- s.setValue("MainWinSize", size());
- s.setValue("MainWinPos", pos());
+ saveStateToSettings(s);
+}
+
+void MainWin::saveStateToSettings(UiSettings &s) {
+ s.setValue("MainWinSize", _normalSize);
+ s.setValue("MainWinPos", _normalPos);
s.setValue("MainWinState", saveState());
+ s.setValue("MainWinGeometry", saveGeometry());
+ s.setValue("MainWinMinimized", isMinimized());
+ s.setValue("MainWinMaximized", isMaximized());
+ s.setValue("MainWinHidden", _isHidden);
+}
+
+void MainWin::restoreStateFromSettings(UiSettings &s) {
+ _normalSize = s.value("MainWinSize", size()).toSize();
+ _normalPos = s.value("MainWinPos", pos()).toPoint();
+ bool maximized = s.value("MainWinMaximized", false).toBool();
+
+ restoreGeometry(s.value("MainWinGeometry").toByteArray());
+
+ if(maximized) {
+ // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
+ resize(_normalSize);
+ move(_normalPos);
+ }
+
+ restoreState(s.value("MainWinState").toByteArray());
+
+ _isHidden = false;
+ if(s.value("MainWinHidden").toBool())
+ hideToTray();
+ else if(s.value("MainWinMinimized").toBool())
+ showMinimized();
+ else if(maximized)
+ showMaximized();
+ else
+ show();
}
void MainWin::updateIcon() {
this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
this, SLOT(on_actionDebugMessageModel_triggered())));
+ coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
+ this, SLOT(on_actionDebugHotList_triggered())));
coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
this, SLOT(on_actionDebugLog_triggered())));
+
+ // Navigation
+ coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot buffer"), coll,
+ this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
}
void MainWin::setupMenus() {
_helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
_helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
_helpDebugMenu->addAction(coll->action("DebugMessageModel"));
+ _helpDebugMenu->addAction(coll->action("DebugHotList"));
_helpDebugMenu->addAction(coll->action("DebugLog"));
}
connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
}
+void MainWin::setupHotList() {
+ FlatProxyModel *flatProxy = new FlatProxyModel(this);
+ flatProxy->setSourceModel(Client::bufferModel());
+ _bufferHotList = new BufferHotListFilter(flatProxy);
+}
+
void MainWin::saveStatusBarStatus(bool enabled) {
QtUiSettings uiSettings;
uiSettings.setValue("ShowStatusBar", enabled);
}
#endif
+/********************************************************************************************************/
+
+bool MainWin::event(QEvent *event) {
+ if(event->type() == QEvent::WindowActivate)
+ QtUi::closeNotifications();
+ return QMainWindow::event(event);
+}
+
+void MainWin::moveEvent(QMoveEvent *event) {
+ if(!(windowState() & Qt::WindowMaximized))
+ _normalPos = event->pos();
+
+ QMainWindow::moveEvent(event);
+}
+
+void MainWin::resizeEvent(QResizeEvent *event) {
+ if(!(windowState() & Qt::WindowMaximized))
+ _normalSize = event->size();
+
+ QMainWindow::resizeEvent(event);
+}
+
void MainWin::closeEvent(QCloseEvent *event) {
QtUiSettings s;
QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
Q_ASSERT(app);
- if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
- toggleMinimizedToTray();
+ if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
+ hideToTray();
event->ignore();
} else {
event->accept();
}
}
-bool MainWin::event(QEvent *event) {
- if(event->type() == QEvent::WindowActivate)
- QtUi::closeNotifications();
- return QMainWindow::event(event);
-}
-
void MainWin::changeEvent(QEvent *event) {
- if(event->type() == QEvent::WindowStateChange) {
- if(windowState() & Qt::WindowMinimized) {
- QtUiSettings s;
- if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
- hideToTray();
- event->accept();
- return;
- }
- }
- }
-
#ifdef Q_WS_WIN
- else if(event->type() == QEvent::ActivationChange)
+ if(event->type() == QEvent::ActivationChange)
dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
#endif
- event->ignore();
+ QMainWindow::changeEvent(event);
}
void MainWin::hideToTray() {
}
hide();
systemTray()->setIconVisible();
+ _isHidden = true;
}
void MainWin::toggleMinimizedToTray() {
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
}
- move(frameGeometry().topLeft()); // avoid placement policies
+ // this does not actually work on all platforms... and causes more evil than good
+ // move(frameGeometry().topLeft()); // avoid placement policies
show();
raise();
activateWindow();
+ _isHidden = false;
}
void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
else net->requestDisconnect();
}
+void MainWin::on_jumpHotBuffer_triggered() {
+ if(!_bufferHotList->rowCount())
+ return;
+
+ QModelIndex topIndex = _bufferHotList->index(0, 0);
+ BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
+ Client::bufferModel()->switchToBuffer(bufferId);
+}
+
void MainWin::on_actionDebugNetworkModel_triggered() {
QTreeView *view = new QTreeView;
view->setAttribute(Qt::WA_DeleteOnClose);
view->show();
}
-void MainWin::on_actionDebugBufferViewOverlay_triggered() {
+void MainWin::on_actionDebugHotList_triggered() {
QTreeView *view = new QTreeView;
view->setAttribute(Qt::WA_DeleteOnClose);
- view->setWindowTitle("Debug BufferViewOverlay View");
- BufferViewOverlayFilter *filter = new BufferViewOverlayFilter(Client::bufferModel(), Client::bufferViewOverlay());
- filter->setParent(view);
- view->setModel(filter);
- view->setColumnWidth(0, 250);
- view->setColumnWidth(1, 250);
- view->setColumnWidth(2, 80);
- view->resize(610, 300);
+ view->setModel(_bufferHotList);
view->show();
}
+void MainWin::on_actionDebugBufferViewOverlay_triggered() {
+ DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
+ overlay->setAttribute(Qt::WA_DeleteOnClose);
+ overlay->show();
+}
+
void MainWin::on_actionDebugMessageModel_triggered() {
QTableView *view = new QTableView(0);
DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
logWidget->show();
}
-void MainWin::saveStateToSession(const QString &sessionId) {
- return;
- SessionSettings s(sessionId);
-
- s.setValue("MainWinSize", size());
- s.setValue("MainWinPos", pos());
- s.setValue("MainWinState", saveState());
-}
-
-void MainWin::saveStateToSessionSettings(SessionSettings & s)
-{
- s.setValue("MainWinSize", size());
- s.setValue("MainWinPos", pos());
- s.setValue("MainWinState", saveState());
-}
-
void MainWin::showStatusBarMessage(const QString &message) {
statusBar()->showMessage(message, 10000);
}