Skip to content

Commit

Permalink
Merge remote-tracking branch 'fish-face/merge_arbitrary-jumpkeys' int…
Browse files Browse the repository at this point in the history
…o romibisCustomBuilds
  • Loading branch information
romibi committed Mar 17, 2018
2 parents 0db2366 + 1cad60e commit 097f7ee
Show file tree
Hide file tree
Showing 25 changed files with 514 additions and 125 deletions.
6 changes: 6 additions & 0 deletions src/client/buffersettings.h
Expand Up @@ -21,6 +21,8 @@
#ifndef BUFFERSETTINGS_H
#define BUFFERSETTINGS_H

#include <QKeySequence>

#include "clientsettings.h"
#include "message.h"
#include "types.h"
Expand Down Expand Up @@ -58,6 +60,10 @@ class BufferSettings : public ClientSettings
inline void setServerNoticesTarget(int target) { setLocalValue("ServerNoticesTarget", target); }
inline int errorMsgsTarget() { return localValue("ErrorMsgsTarget", DefaultBuffer).toInt(); }
inline void setErrorMsgsTarget(int target) { setLocalValue("ErrorMsgsTarget", target); }

// quick accessor shortcuts
inline QKeySequence shortcut() { return qvariant_cast<QKeySequence>(localValue("Shortcut")); }
inline void setShortcut(QKeySequence sequence) { setLocalValue("Shortcut", sequence); }
};


Expand Down
26 changes: 0 additions & 26 deletions src/client/clientsettings.cpp
Expand Up @@ -176,32 +176,6 @@ QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &d
return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
}


void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap)
{
QVariantMap variants;
QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
while (mapIter != keyMap.constEnd()) {
variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
++mapIter;
}
setAccountValue("JumpKeyMap", variants);
}


QHash<int, BufferId> CoreAccountSettings::jumpKeyMap()
{
QHash<int, BufferId> keyMap;
QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
QVariantMap::const_iterator mapIter = variants.constBegin();
while (mapIter != variants.constEnd()) {
keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
++mapIter;
}
return keyMap;
}


void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds)
{
QVariantList variants;
Expand Down
3 changes: 0 additions & 3 deletions src/client/clientsettings.h
Expand Up @@ -73,9 +73,6 @@ class CoreAccountSettings : public ClientSettings
QVariantMap retrieveAccountData(AccountId);
void removeAccount(AccountId);

void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
QHash<int, BufferId> jumpKeyMap();

void setBufferViewOverlay(const QSet<int> &viewIds);
QSet<int> bufferViewOverlay();

Expand Down
141 changes: 68 additions & 73 deletions src/qtui/mainwin.cpp
Expand Up @@ -56,6 +56,8 @@
#include "actioncollection.h"
#include "bufferhotlistfilter.h"
#include "buffermodel.h"
#include "buffersettings.h"
#include "buffershortcutpopup.h"
#include "bufferview.h"
#include "bufferviewoverlay.h"
#include "bufferviewoverlayfilter.h"
Expand Down Expand Up @@ -95,6 +97,7 @@
#include "qtuisettings.h"
#include "qtuistyle.h"
#include "receivefiledlg.h"
#include "quickaccessorssettingspage.h"
#include "settingsdlg.h"
#include "settingspagedlg.h"
#include "statusnotifieritem.h"
Expand Down Expand Up @@ -209,6 +212,7 @@ void MainWin::init()
connect(Client::instance(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(bufferShortcutsChanged(BufferId)), SLOT(updateQuickAccessor(BufferId)));

connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
Expand Down Expand Up @@ -445,6 +449,13 @@ void MainWin::setupActions()
configureShortcutsAct->setMenuRole(QAction::NoRole);
coll->addAction("ConfigureShortcuts", configureShortcutsAct);

#ifdef HAVE_KDE
QAction *configureQuickAccessorsAct = new Action(SmallIcon("configure-shortcuts"), tr("Configure &Quick Accessors..."), coll,
this, SLOT(showQuickAccessorsDlg()));
configureQuickAccessorsAct->setMenuRole(QAction::NoRole);
coll->addAction("ConfigureQuickAccessors", configureQuickAccessorsAct);
#endif

#ifdef Q_OS_MAC
QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
this, SLOT(showSettingsDlg()));
Expand Down Expand Up @@ -486,61 +497,11 @@ void MainWin::setupActions()

coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));

coll->addAction("SetBufferShortcut", new Action(tr("Set Current Buffer's Shortcut"), coll,
this, SLOT(setBufferShortcut()), QKeySequence(Qt::CTRL + Qt::Key_J)));
coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));

// Jump keys
#ifdef Q_OS_MAC
const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
const int jumpModifier = Qt::ControlModifier;
#else
const int bindModifier = Qt::ControlModifier;
const int jumpModifier = Qt::AltModifier;
#endif

coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);

coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);

// Buffer navigation
coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
Expand Down Expand Up @@ -596,6 +557,7 @@ void MainWin::setupMenus()
_settingsMenu = menuBar()->addMenu(tr("&Settings"));
#ifdef HAVE_KDE
_settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
_settingsMenu->addAction(coll->action("ConfigureQuickAccessors"));
_settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
#else
_settingsMenu->addAction(coll->action("ConfigureShortcuts"));
Expand Down Expand Up @@ -1171,6 +1133,35 @@ void MainWin::connectedToCore()
}

setConnectedState();
setupQuickAccessors();
}


void MainWin::setupQuickAccessors() {
QList<BufferId> allBufferIds = Client::networkModel()->allBufferIds();
QListIterator<BufferId> bufIter(allBufferIds);

foreach(ActionCollection *coll, QtUi::quickAccessorActionCollections()) {
coll->clear();
}

while(bufIter.hasNext()) {
updateQuickAccessor(bufIter.next());
}
}


void MainWin::updateQuickAccessor(BufferId id) {
BufferInfo info = Client::networkModel()->bufferInfo(id);
if(info.type() & (BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer)) {
QString networkName = Client::networkModel()->networkName(id);

BufferSettings settings(id);
Action *a = new Action(info.bufferName(), QtUi::quickAccessorActionCollection(networkName), this, SLOT(onJumpKey()));
a->setShortcut(settings.shortcut(), Action::ActiveShortcut);
a->setProperty("BufferId", qVariantFromValue(id));
QtUi::quickAccessorActionCollection(networkName)->addAction(QString("QuickAccessor%1").arg(id.toInt()), a);
}
}


Expand Down Expand Up @@ -1518,8 +1509,11 @@ void MainWin::showShortcutsDlg()
dlg.addCollection(coll, coll->property("Category").toString());
dlg.configure(true);
#else
SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
dlg.exec();
SettingsDlg *dlg = new SettingsDlg();
setupQuickAccessors();
dlg->registerSettingsPage(new ShortcutsSettingsPage(QtUi::allActionCollections(), QtUi::actionCollections().keys(), dlg));
dlg->registerSettingsPage(new QuickAccessorsSettingsPage(dlg));
dlg->show();
#endif
}

Expand All @@ -1539,6 +1533,16 @@ void MainWin::showNewTransferDlg(const QUuid &transferId)
}


void MainWin::showQuickAccessorsDlg()
{
#ifdef HAVE_KDE
setupQuickAccessors();
SettingsPageDlg dlg(new QuickAccessorsSettingsPage(this), this);
dlg.exec();
#endif
}


void MainWin::onFullScreenToggled()
{
// Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
Expand Down Expand Up @@ -1776,34 +1780,25 @@ void MainWin::on_bufferSearch_triggered()
}


void MainWin::onJumpKey()
void MainWin::setBufferShortcut()
{
QAction *action = qobject_cast<QAction *>(sender());
if (!action || !Client::bufferModel())
return;
int idx = action->property("Index").toInt();

if (_jumpKeyMap.isEmpty())
_jumpKeyMap = CoreAccountSettings().jumpKeyMap();

if (!_jumpKeyMap.contains(idx))
return;

BufferId buffer = _jumpKeyMap.value(idx);
if (buffer.isValid())
Client::bufferModel()->switchToBuffer(buffer);
BufferInfo info = Client::bufferModel()->standardSelectionModel()->currentIndex().data(NetworkModel::BufferInfoRole).value<BufferInfo>();
BufferShortcutPopup *popup = new BufferShortcutPopup(info, this);
connect(popup, SIGNAL(keySequenceChanged(BufferId)), this, SLOT(updateQuickAccessor(BufferId)));
//NetworkModelController::handleBufferAction(NetworkModelController::BufferSetShortcut, (QAction *)0x0);
}


void MainWin::bindJumpKey()
void MainWin::onJumpKey()
{
QAction *action = qobject_cast<QAction *>(sender());
if (!action || !Client::bufferModel())
return;
int idx = action->property("Index").toInt();
BufferId buffer = qvariant_cast<BufferId>(action->property("BufferId"));
BufferInfo info = Client::networkModel()->bufferInfo(buffer);

_jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
if(buffer.isValid())
Client::bufferModel()->switchToBuffer(buffer);
}


Expand Down
6 changes: 4 additions & 2 deletions src/qtui/mainwin.h
Expand Up @@ -91,6 +91,7 @@ class MainWin

public slots:
void showStatusBarMessage(const QString &message);
void setBufferShortcut();
void hideCurrentBuffer();
void nextBufferView(); //!< Activate the next bufferview
void previousBufferView(); //!< Activate the previous bufferview
Expand Down Expand Up @@ -131,6 +132,8 @@ private slots:
void showPasswordChangeDlg();
void showNewTransferDlg(const QUuid &transferId);
void onFullScreenToggled();
void showQuickAccessorsDlg();
void updateQuickAccessor(BufferId);

void handleCoreConnectionError(const QString &errorMsg);
void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
Expand All @@ -151,7 +154,6 @@ private slots:
void on_actionDebugHotList_triggered();
void on_actionDebugLog_triggered();

void bindJumpKey();
void onJumpKey();

void clientNetworkCreated(NetworkId);
Expand Down Expand Up @@ -200,6 +202,7 @@ private slots:
void setupTitleSetter();
void setupToolBars();
void setupHotList();
void setupQuickAccessors();

void updateIcon();
void enableMenus();
Expand All @@ -224,7 +227,6 @@ private slots:
QPoint _normalPos; //!< Position of the non-maximized window

BufferHotListFilter *_bufferHotList;
QHash<int, BufferId> _jumpKeyMap;
int _activeBufferViewIndex;

bool _aboutToQuit; //closeEvent can occur multiple times on OSX
Expand Down
57 changes: 57 additions & 0 deletions src/qtui/settingspages/quickaccessorssettingspage.cpp
@@ -0,0 +1,57 @@
#include "quickaccessorssettingspage.h"

#include "qtui.h"
#include "client.h"
#include "clientsettings.h"
#include "bufferviewconfig.h"
#include "buffermodel.h"
#include "buffersettings.h"
#include "bufferview.h"

QuickAccessorsSettingsPage::QuickAccessorsSettingsPage(QWidget *parent)
: ShortcutsSettingsPage(QtUi::allActionCollections(), QtUi::quickAccessorActionCollections().keys(), parent, tr("Interface"), tr("Quick Accessors"))
{

}


void QuickAccessorsSettingsPage::load() {
//We need to replace _shortcutsModel with our own class which saves things correctly.
delete _shortcutsModel;

_shortcutsModel = new QuickAccessorsModel(QtUi::allActionCollections(), this);
_shortcutsModel->load();
_shortcutsFilter->setSourceModel(_shortcutsModel);
connect(_shortcutsModel, SIGNAL(hasChanged(bool)), SLOT(setChangedState(bool)));
ui.keySequenceWidget->setModel(_shortcutsModel);

ui.shortcutsView->expandAll();

setChangedState(false);

SettingsPage::load();
}



QuickAccessorsModel::QuickAccessorsModel(const QHash<QString, ActionCollection *> &colls, QWidget *parent)
: ShortcutsModel(colls, parent)
{

}


void QuickAccessorsModel::commit() {
BufferId id;
foreach(Item *catItem, _categoryItems) {
foreach(Item *actItem, catItem->actionItems) {
// Save the shortcut to the buffer's settings.
// NOTE: This could break if the user invalidates the BufferId in between
// showing the settingspage and saving it. (Do we care?),
id = qvariant_cast<BufferId>(actItem->action->property("BufferId"));
BufferSettings s(id);
s.setShortcut(actItem->shortcut);
}
}
ShortcutsModel::commit();
}

0 comments on commit 097f7ee

Please sign in to comment.