Skip to content

Commit

Permalink
Drop dead-end concept of macros, it was too confusing, we will go for…
Browse files Browse the repository at this point in the history
… something more powerful and easier to use directly, references #42
  • Loading branch information
Emdek committed Feb 1, 2015
1 parent b93da29 commit f65bc4d
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 733 deletions.
5 changes: 0 additions & 5 deletions resources/macros/default.ini

This file was deleted.

5 changes: 0 additions & 5 deletions resources/macros/platform.ini

This file was deleted.

2 changes: 0 additions & 2 deletions resources/resources.qrc
Expand Up @@ -124,8 +124,6 @@
<file>icons/zoom-out.png</file>
<file>keyboard/default.ini</file>
<file>keyboard/platform.ini</file>
<file>macros/default.ini</file>
<file>macros/platform.ini</file>
<file>other/adblock.ini</file>
<file>other/menuBar.json</file>
<file>other/menuButton.json</file>
Expand Down
4 changes: 0 additions & 4 deletions resources/schemas/options.ini
Expand Up @@ -30,10 +30,6 @@ value=true
type=string
value=qtwebkit

[Browser/ActionMacrosProfilesOrder]
type=string
value=platform,default

[Browser/AlwaysAskWhereToSaveDownload]
type=bool
value=true
Expand Down
114 changes: 1 addition & 113 deletions src/core/ActionsManager.cpp
Expand Up @@ -309,7 +309,7 @@ int ActionsManagerHelper::registerAction(int identifier, const QString &text, co

void ActionsManagerHelper::optionChanged(const QString &option)
{
if ((option == QLatin1String("Browser/ActionMacrosProfilesOrder") || option == QLatin1String("Browser/KeyboardShortcutsProfilesOrder")) && reloadShortcutsTimer == 0)
if (option == QLatin1String("Browser/KeyboardShortcutsProfilesOrder") && reloadShortcutsTimer == 0)
{
reloadShortcutsTimer = startTimer(250);
}
Expand Down Expand Up @@ -406,38 +406,6 @@ void ActionsManager::actionTriggered(bool checked)
}
}

void ActionsManager::macroTriggered()
{
if (!m_helper)
{
initialize();
}

QShortcut *shortcut = qobject_cast<QShortcut*>(sender());

if (shortcut)
{
m_mutex.lock();

for (int i = 0; i < m_macroShortcuts.count(); ++i)
{
if (m_macroShortcuts[i].second.contains(shortcut))
{
const QVector<int> actions = m_helper->macroDefinitions.value(m_macroShortcuts[i].first).actions;

for (int j = 0; j < actions.count(); ++j)
{
triggerAction(actions[j]);
}

break;
}
}

m_mutex.unlock();
}
}

void ActionsManager::updateShortcuts()
{
if (!m_helper)
Expand Down Expand Up @@ -478,23 +446,6 @@ void ActionsManager::updateShortcuts()
m_actionShortcuts.append(qMakePair(i, shortcuts));
}

for (int i = 0; i < m_helper->macroDefinitions.count(); ++i)
{
QVector<QShortcut*> shortcuts;
shortcuts.reserve(m_helper->macroDefinitions[i].shortcuts.count());

for (int j = 0; j < m_helper->macroDefinitions[i].shortcuts.count(); ++j)
{
QShortcut *shortcut = new QShortcut(m_helper->macroDefinitions[i].shortcuts[j], m_mainWindow);

shortcuts.append(shortcut);

connect(shortcut, SIGNAL(activated()), this, SLOT(macroTriggered()));
}

m_macroShortcuts.append(qMakePair(i, shortcuts));
}

m_mutex.unlock();
}

Expand Down Expand Up @@ -561,59 +512,6 @@ void ActionsManager::loadShortcuts()
m_helper->actionDefinitions[i].shortcuts = actionShortcuts.value(i);
}

m_helper->macroDefinitions.clear();

const QStringList macroProfiles = SettingsManager::getValue(QLatin1String("Browser/ActionMacrosProfilesOrder")).toStringList();

for (int i = 0; i < macroProfiles.count(); ++i)
{
const QString path = SessionsManager::getProfilePath() + QLatin1String("/macros/") + macroProfiles.at(i) + QLatin1String(".ini");
const QSettings profile((QFile::exists(path) ? path : QLatin1String(":/macros/") + macroProfiles.at(i) + QLatin1String(".ini")), QSettings::IniFormat);
const QStringList macros = profile.childGroups();

for (int j = 0; j < macros.count(); ++j)
{
const QStringList rawActions = profile.value(macros.at(j) + QLatin1String("/actions"), QString()).toStringList();
QVector<int> actions;

for (int k = 0; k < rawActions.count(); ++k)
{
const int action = ActionsManager::getActionIdentifier(rawActions.at(k));

if (action >= 0)
{
actions.append(action);
}
}

const QStringList rawShortcuts = profile.value(macros.at(j) + QLatin1String("/shortcuts"), QString()).toString().split(QLatin1Char(' '), QString::SkipEmptyParts);
QVector<QKeySequence> shortcuts;
shortcuts.reserve(rawShortcuts.count());

for (int k = 0; k < rawShortcuts.count(); ++k)
{
const QKeySequence shortcut(rawShortcuts.at(k));

if (!shortcut.isEmpty() && !allShortcuts.contains(shortcut))
{
shortcuts.append(shortcut);
allShortcuts.append(shortcut);
}
}

if (actions.isEmpty() || shortcuts.isEmpty())
{
continue;
}

MacroDefinition macro;
macro.actions = actions;
macro.shortcuts = shortcuts;

m_helper->macroDefinitions.append(macro);
}
}

m_mutex.unlock();

emit m_helper->shortcutsChanged();
Expand Down Expand Up @@ -725,16 +623,6 @@ QList<ActionDefinition> ActionsManager::getActionDefinitions()
return m_helper->actionDefinitions.toList();
}

QList<MacroDefinition> ActionsManager::getMacroDefinitions()
{
if (!m_helper)
{
initialize();
}

return m_helper->macroDefinitions.toList();
}

QList<ToolBarDefinition> ActionsManager::getToolBarDefinitions()
{
if (!m_helper)
Expand Down
10 changes: 0 additions & 10 deletions src/core/ActionsManager.h
Expand Up @@ -72,13 +72,6 @@ struct ActionDefinition
ActionDefinition() : identifier(-1), isCheckable(false), isChecked(false), isEnabled(true) {}
};

struct MacroDefinition
{
// QString script;
QVector<int> actions;
QVector<QKeySequence> shortcuts;
};

class ActionsManager;
class MainWindow;
class Window;
Expand All @@ -95,7 +88,6 @@ class ActionsManagerHelper : public QObject

int reloadShortcutsTimer;
QVector<ActionDefinition> actionDefinitions;
QVector<MacroDefinition> macroDefinitions;
QHash<QString, ToolBarDefinition> toolBarDefinitions;

protected slots:
Expand All @@ -122,7 +114,6 @@ class ActionsManager : public QObject
static Action* getAction(int identifier, QObject *parent);
static QString getActionName(int identifier);
static QList<ActionDefinition> getActionDefinitions();
static QList<MacroDefinition> getMacroDefinitions();
static QList<ToolBarDefinition> getToolBarDefinitions();
static ActionDefinition getActionDefinition(int identifier);
static ToolBarDefinition getToolBarDefinition(const QString &toolBar);
Expand All @@ -135,7 +126,6 @@ class ActionsManager : public QObject
protected slots:
void actionTriggered();
void actionTriggered(bool checked);
void macroTriggered();
void updateShortcuts();

private:
Expand Down

0 comments on commit f65bc4d

Please sign in to comment.