Skip to content

Commit 0e06241

Browse files
v0.18 websearch
1 parent 19f7524 commit 0e06241

12 files changed

+109
-205
lines changed

websearch/metadata.json

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
2-
"id" : "org.albert.extension.websearch",
3-
"name" : "WebSearch",
4-
"version" : "1.0",
5-
"platform" : "All",
6-
"group" : "Extensions",
7-
"author" : "Manuel Schneider",
8-
"dependencies" : [],
2+
"id": "websearch",
3+
"name": "WebSearch",
4+
"version": "1.0",
5+
"authors": ["@manuelschneid3r"],
96
"enabledbydefault": true
107
}

websearch/src/configwidget.cpp

+13-18
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#include <QStandardPaths>
66
#include "configwidget.h"
77
#include "enginesmodel.h"
8-
#include "extension.h"
8+
#include "plugin.h"
99
#include "searchengineeditor.h"
1010

11-
/** ***************************************************************************/
12-
Websearch::ConfigWidget::ConfigWidget(Extension *extension, QWidget *parent)
11+
12+
ConfigWidget::ConfigWidget(Plugin *extension, QWidget *parent)
1313
: QWidget(parent), extension_(extension) {
1414

1515
ui.setupUi(this);
@@ -35,15 +35,14 @@ Websearch::ConfigWidget::ConfigWidget(Extension *extension, QWidget *parent)
3535
}
3636

3737

38+
ConfigWidget::~ConfigWidget()
39+
{
3840

39-
/** ***************************************************************************/
40-
Websearch::ConfigWidget::~ConfigWidget() {
4141
}
4242

4343

44-
45-
/** ***************************************************************************/
46-
void Websearch::ConfigWidget::onActivated(QModelIndex index) {
44+
void ConfigWidget::onActivated(QModelIndex index)
45+
{
4746
int row = index.row();
4847
SearchEngineEditor searchEngineEditor(extension_->engines()[static_cast<ulong>(row)], this);
4948

@@ -59,10 +58,8 @@ void Websearch::ConfigWidget::onActivated(QModelIndex index) {
5958
}
6059

6160

62-
63-
/** ***************************************************************************/
64-
void Websearch::ConfigWidget::onButton_new() {
65-
61+
void ConfigWidget::onButton_new()
62+
{
6663
// Open search engine editor
6764
SearchEngine searchEngine;
6865
searchEngine.iconPath = ":default";
@@ -90,9 +87,8 @@ void Websearch::ConfigWidget::onButton_new() {
9087
}
9188

9289

93-
94-
/** ***************************************************************************/
95-
void Websearch::ConfigWidget::onButton_remove() {
90+
void ConfigWidget::onButton_remove()
91+
{
9692
// Ask if sure
9793
int row = ui.tableView_searches->currentIndex().row();
9894
QString engineName = ui.tableView_searches->model()
@@ -108,9 +104,8 @@ void Websearch::ConfigWidget::onButton_remove() {
108104
}
109105

110106

111-
112-
/** ***************************************************************************/
113-
void Websearch::ConfigWidget::onButton_restoreDefaults() {
107+
void ConfigWidget::onButton_restoreDefaults()
108+
{
114109
QMessageBox::StandardButton reply =
115110
QMessageBox::question(this, "Sure?",
116111
QString("Do you really want to restore the default search engines?"),

websearch/src/configwidget.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
#include <QWidget>
55
#include "ui_configwidget.h"
66

7-
namespace Websearch {
8-
9-
class Extension;
7+
class Plugin;
108
class EnginesModel;
119

1210
class ConfigWidget final : public QWidget
@@ -15,7 +13,7 @@ class ConfigWidget final : public QWidget
1513

1614
public:
1715

18-
explicit ConfigWidget(Extension *extension, QWidget *parent = 0);
16+
explicit ConfigWidget(Plugin *extension, QWidget *parent = 0);
1917
~ConfigWidget();
2018
Ui::ConfigWidget ui;
2119

@@ -26,8 +24,6 @@ class ConfigWidget final : public QWidget
2624
void onButton_remove();
2725
void onButton_restoreDefaults();
2826

29-
Extension *extension_;
27+
Plugin *extension_;
3028
EnginesModel *enginesModel_;
3129
};
32-
33-
}

websearch/src/configwidget.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ui version="4.0">
3-
<class>Websearch::ConfigWidget</class>
4-
<widget class="QWidget" name="Websearch::ConfigWidget">
3+
<class>ConfigWidget</class>
4+
<widget class="QWidget" name="ConfigWidget">
55
<layout class="QVBoxLayout" name="verticalLayout">
66
<item>
77
<widget class="QTableView" name="tableView_searches">

websearch/src/enginesmodel.cpp

+34-50
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,37 @@
99
#include <QStandardPaths>
1010
#include <QUuid>
1111
#include "enginesmodel.h"
12-
#include "extension.h"
12+
#include "plugin.h"
1313
#include "searchengine.h"
1414

1515
namespace {
16-
1716
enum class Section{ Name, Trigger, URL} ;
1817
const int sectionCount = 3;
19-
2018
std::map<QString,QIcon> iconCache;
21-
2219
}
2320

2421

25-
/** ***************************************************************************/
26-
Websearch::EnginesModel::EnginesModel(Extension *extension, QObject *parent)
27-
: QAbstractTableModel(parent), extension_(extension) {
22+
EnginesModel::EnginesModel(Plugin *extension, QObject *parent)
23+
: QAbstractTableModel(parent), extension_(extension)
24+
{
25+
2826
}
2927

3028

31-
/** ***************************************************************************/
32-
int Websearch::EnginesModel::rowCount(const QModelIndex &) const {
29+
int EnginesModel::rowCount(const QModelIndex &) const
30+
{
3331
return static_cast<int>(extension_->engines().size());
3432
}
3533

3634

37-
38-
/** ***************************************************************************/
39-
int Websearch::EnginesModel::columnCount(const QModelIndex &) const {
35+
int EnginesModel::columnCount(const QModelIndex &) const
36+
{
4037
return sectionCount;
4138
}
4239

4340

44-
45-
/** ***************************************************************************/
46-
QVariant Websearch::EnginesModel::headerData(int section, Qt::Orientation orientation, int role) const {
41+
QVariant EnginesModel::headerData(int section, Qt::Orientation orientation, int role) const
42+
{
4743
// No sanity check necessary since
4844
if ( section < 0 || sectionCount <= section )
4945
return QVariant();
@@ -81,9 +77,8 @@ QVariant Websearch::EnginesModel::headerData(int section, Qt::Orientation orient
8177
}
8278

8379

84-
85-
/** ***************************************************************************/
86-
QVariant Websearch::EnginesModel::data(const QModelIndex &index, int role) const {
80+
QVariant EnginesModel::data(const QModelIndex &index, int role) const
81+
{
8782
if ( !index.isValid() ||
8883
index.row() >= static_cast<int>(extension_->engines().size()) ||
8984
index.column() >= sectionCount )
@@ -119,9 +114,8 @@ QVariant Websearch::EnginesModel::data(const QModelIndex &index, int role) const
119114
}
120115

121116

122-
123-
/** ***************************************************************************/
124-
bool Websearch::EnginesModel::setData(const QModelIndex &index, const QVariant &value, int role) {
117+
bool EnginesModel::setData(const QModelIndex &index, const QVariant &value, int role)
118+
{
125119
if ( !index.isValid() ||
126120
index.row() >= static_cast<int>(extension_->engines().size()) ||
127121
index.column() >= sectionCount)
@@ -168,14 +162,14 @@ bool Websearch::EnginesModel::setData(const QModelIndex &index, const QVariant &
168162

169163
// Create extension dir if necessary
170164
QDir configDir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
171-
if ( !configDir.exists(extension_->Core::Plugin::id()) ) {
172-
if ( !configDir.mkdir(extension_->Core::Plugin::id()) ) {
165+
if ( !configDir.exists(extension_->Core::PluginInstance::id()) ) {
166+
if ( !configDir.mkdir(extension_->Core::PluginInstance::id()) ) {
173167
qWarning() << "Could not create extension data dir.";
174168
return false;
175169
}
176170
}
177171

178-
configDir.cd(extension_->Core::Plugin::id());
172+
configDir.cd(extension_->Core::PluginInstance::id());
179173

180174
// Build the new random path
181175
QString newFilePath = configDir.filePath(QString("%1.%2")
@@ -206,19 +200,17 @@ bool Websearch::EnginesModel::setData(const QModelIndex &index, const QVariant &
206200
}
207201

208202

209-
210-
/** ***************************************************************************/
211-
Qt::ItemFlags Websearch::EnginesModel::flags(const QModelIndex &index) const {
203+
Qt::ItemFlags EnginesModel::flags(const QModelIndex &index) const
204+
{
212205
if (index.isValid())
213206
return QAbstractTableModel::flags(index) | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
214207
else
215208
return QAbstractTableModel::flags(index) | Qt::ItemIsDropEnabled;
216209
}
217210

218211

219-
220-
/** ***************************************************************************/
221-
bool Websearch::EnginesModel::insertRows(int position, int rows, const QModelIndex &) {
212+
bool EnginesModel::insertRows(int position, int rows, const QModelIndex &)
213+
{
222214
if ( position < 0 || rows < 1 ||
223215
static_cast<int>(extension_->engines().size()) < position)
224216
return false;
@@ -235,9 +227,8 @@ bool Websearch::EnginesModel::insertRows(int position, int rows, const QModelInd
235227
}
236228

237229

238-
239-
/** ***************************************************************************/
240-
bool Websearch::EnginesModel::removeRows(int position, int rows, const QModelIndex &) {
230+
bool EnginesModel::removeRows(int position, int rows, const QModelIndex &)
231+
{
241232
if ( position < 0 || rows < 1 ||
242233
static_cast<int>(extension_->engines().size()) < position + rows)
243234
return false;
@@ -252,10 +243,9 @@ bool Websearch::EnginesModel::removeRows(int position, int rows, const QModelInd
252243
}
253244

254245

255-
256-
/** ***************************************************************************/
257-
bool Websearch::EnginesModel::moveRows(const QModelIndex &srcParent, int srcRow, int cnt,
258-
const QModelIndex &dstParent, int dstRow) {
246+
bool EnginesModel::moveRows(const QModelIndex &srcParent, int srcRow, int cnt,
247+
const QModelIndex &dstParent, int dstRow)
248+
{
259249
if ( srcRow < 0 || cnt < 1 || dstRow < 0 ||
260250
static_cast<int>(extension_->engines().size()) < srcRow + cnt - 1 ||
261251
static_cast<int>(extension_->engines().size()) < dstRow ||
@@ -279,29 +269,23 @@ bool Websearch::EnginesModel::moveRows(const QModelIndex &srcParent, int srcRow,
279269
}
280270

281271

282-
283-
/** ***************************************************************************/
284-
void Websearch::EnginesModel::restoreDefaults() {
272+
void EnginesModel::restoreDefaults()
273+
{
285274
beginResetModel();
286275
extension_->restoreDefaultEngines();
287276
endResetModel();
288277
}
289278

290279

291-
292-
/** ***************************************************************************/
293-
Qt::DropActions Websearch::EnginesModel::supportedDropActions() const {
280+
Qt::DropActions EnginesModel::supportedDropActions() const
281+
{
294282
return Qt::MoveAction;
295283
}
296284

297285

298-
299-
/** ***************************************************************************/
300-
bool Websearch::EnginesModel::dropMimeData(const QMimeData *data,
301-
Qt::DropAction /*action*/,
302-
int dstRow,
303-
int /*column*/,
304-
const QModelIndex &/*parent*/) {
286+
bool EnginesModel::dropMimeData(const QMimeData *data, Qt::DropAction /*action*/,
287+
int dstRow, int /*column*/, const QModelIndex &/*parent*/)
288+
{
305289
QByteArray encoded = data->data("application/x-qabstractitemmodeldatalist");
306290
QDataStream stream(&encoded, QIODevice::ReadOnly);
307291
int srcRow = 0;

websearch/src/enginesmodel.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
#pragma once
44
#include <QAbstractTableModel>
55

6-
namespace Websearch {
7-
8-
class Extension;
6+
class Plugin;
97

108
class EnginesModel final : public QAbstractTableModel
119
{
1210
Q_OBJECT
1311

1412
public:
1513

16-
EnginesModel(Extension *extension, QObject *parent = Q_NULLPTR);
14+
EnginesModel(Plugin *extension, QObject *parent = Q_NULLPTR);
1715

1816
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
1917
int columnCount(const QModelIndex & parent = QModelIndex()) const override;
@@ -31,8 +29,6 @@ class EnginesModel final : public QAbstractTableModel
3129

3230
private:
3331

34-
Extension *extension_;
32+
Plugin *extension_;
3533

3634
};
37-
38-
}

0 commit comments

Comments
 (0)