pull/9/head
reionwong 4 years ago
parent aa7575cbb5
commit 8bab1ec0f9

@ -3,5 +3,6 @@
<file>qml/main.qml</file> <file>qml/main.qml</file>
<file>qml/GridItemDelegate.qml</file> <file>qml/GridItemDelegate.qml</file>
<file>qml/AllAppsView.qml</file> <file>qml/AllAppsView.qml</file>
<file>qml/CategoryView.qml</file>
</qresource> </qresource>
</RCC> </RCC>

@ -45,7 +45,7 @@ ListView {
model: Math.ceil(control.modelCount / control.pageCount) model: Math.ceil(control.modelCount / control.pageCount)
maximumFlickVelocity: 10000 maximumFlickVelocity: 10000
highlightMoveDuration: 100 highlightMoveDuration: 300
preferredHighlightBegin: 0 preferredHighlightBegin: 0
preferredHighlightEnd: 0 preferredHighlightEnd: 0
@ -73,6 +73,11 @@ ListView {
} }
} }
DropArea {
anchors.fill: parent
z: -1
}
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
z: -1 z: -1

@ -0,0 +1,5 @@
import QtQuick 2.0
Item {
}

@ -35,6 +35,8 @@ Item {
property int pageCount: 0 property int pageCount: 0
Drag.active: iconMouseArea.drag.active Drag.active: iconMouseArea.drag.active
Drag.mimeData: [model.appId]
Drag.keys: ["cutefish-launcher"]
Drag.dragType: Drag.Automatic Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.MoveAction Drag.supportedActions: Qt.MoveAction
Drag.hotSpot.x: icon.width / 2 Drag.hotSpot.x: icon.width / 2
@ -181,5 +183,9 @@ Item {
width: parent.width - 2 * FishUI.Units.smallSpacing width: parent.width - 2 * FishUI.Units.smallSpacing
height: fontMetrics.height * 2 height: fontMetrics.height * 2
color: "white" color: "white"
MouseArea {
anchors.fill: parent
}
} }
} }

@ -307,6 +307,12 @@ Item {
} }
} }
Timer {
id: clearSearchTimer
interval: 100
onTriggered: textField.text = ""
}
Connections { Connections {
target: launcher target: launcher
@ -316,7 +322,7 @@ Item {
appView.focus = true appView.focus = true
appView.forceActiveFocus() appView.forceActiveFocus()
} else { } else {
textField.text = "" clearSearchTimer.restart()
} }
} }
} }

@ -30,7 +30,7 @@
#include <KWindowSystem> #include <KWindowSystem>
Launcher::Launcher(QQuickView *w) Launcher::Launcher(bool firstShow, QQuickView *w)
: QQuickView(w) : QQuickView(w)
, m_dockInterface("org.cutefish.Dock", , m_dockInterface("org.cutefish.Dock",
"/Dock", "/Dock",
@ -54,7 +54,7 @@ Launcher::Launcher(QQuickView *w)
setSource(QUrl(QStringLiteral("qrc:/qml/main.qml"))); setSource(QUrl(QStringLiteral("qrc:/qml/main.qml")));
setTitle(tr("Launcher")); setTitle(tr("Launcher"));
setVisible(false); setVisible(firstShow);
// Let the animation in qml be hidden after the execution is complete // Let the animation in qml be hidden after the execution is complete
m_hideTimer->setInterval(200); m_hideTimer->setInterval(200);
@ -114,10 +114,9 @@ void Launcher::showWindow()
void Launcher::hideWindow() void Launcher::hideWindow()
{ {
setVisible(false);
m_showed = false; m_showed = false;
emit showedChanged(); emit showedChanged();
setVisible(false);
} }
void Launcher::toggle() void Launcher::toggle()

@ -36,7 +36,7 @@ class Launcher : public QQuickView
Q_PROPERTY(int bottomMargin READ bottomMargin NOTIFY marginsChanged) Q_PROPERTY(int bottomMargin READ bottomMargin NOTIFY marginsChanged)
public: public:
Launcher(QQuickView *w = nullptr); Launcher(bool firstShow = false, QQuickView *w = nullptr);
int leftMargin() const; int leftMargin() const;
int rightMargin() const; int rightMargin() const;

@ -19,8 +19,31 @@
#include "launcheritem.h" #include "launcheritem.h"
LauncherItem::LauncherItem(QObject *parent) LauncherItem::LauncherItem()
: QObject(parent)
{ {
} }
LauncherItem::LauncherItem(const LauncherItem &item)
{
}
LauncherItem::~LauncherItem()
{
}
QDataStream &operator<<(QDataStream &argument, const LauncherItem &item)
{
argument << item.id << item.name;
return argument;
}
const QDataStream &operator>>(QDataStream &argument, LauncherItem &item)
{
argument >> item.id << item.name;
return argument;
}

@ -21,17 +21,22 @@
#define LAUNCHERITEM_H #define LAUNCHERITEM_H
#include <QObject> #include <QObject>
#include <QDataStream>
class LauncherItem : public QObject class LauncherItem : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString fuke READ fuke CONSTANT)
public: public:
explicit LauncherItem(QObject *parent = nullptr); LauncherItem();
LauncherItem(const LauncherItem &item);
~LauncherItem();
Q_INVOKABLE QString fuke() { return "asd"; }; inline bool operator==(const LauncherItem &other) const { return id == other.id; }
friend QDataStream &operator<<(QDataStream &argument, const LauncherItem &item);
friend const QDataStream &operator>>(QDataStream &argument, LauncherItem &item);
public:
QString id; QString id;
QString name; QString name;
QString genericName; QString genericName;
@ -40,4 +45,6 @@ public:
QStringList args; QStringList args;
}; };
Q_DECLARE_METATYPE(LauncherItem)
#endif // LAUNCHERITEM_H #endif // LAUNCHERITEM_H

@ -19,7 +19,6 @@
#include "launchermodel.h" #include "launchermodel.h"
#include "desktopproperties.h" #include "desktopproperties.h"
#include "launcheritem.h"
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusPendingCallWatcher> #include <QDBusPendingCallWatcher>
@ -45,8 +44,9 @@ static QByteArray detectDesktopEnvironment()
} }
LauncherModel::LauncherModel(QObject *parent) LauncherModel::LauncherModel(QObject *parent)
: QAbstractListModel(parent), : QAbstractListModel(parent)
m_mode(NormalMode) , m_settings("cutefishos", "launcher-applist", this)
, m_mode(NormalMode)
{ {
QtConcurrent::run(LauncherModel::refresh, this); QtConcurrent::run(LauncherModel::refresh, this);
@ -113,11 +113,7 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
LauncherItem *item = m_mode == NormalMode LauncherItem *item = m_mode == NormalMode
? m_items.at(index.row()) ? m_items.at(index.row()) : m_searchItems.at(index.row());
: m_searchItems.at(index.row());
if (!item)
return QVariant();
switch (role) { switch (role) {
case AppIdRole: case AppIdRole:
@ -127,7 +123,10 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
case IconNameRole: case IconNameRole:
return item->iconName; return item->iconName;
case FilterInfoRole: case FilterInfoRole:
return QString(item->name + QStringLiteral(" ") + item->genericName + QStringLiteral(" ") + item->comment); return QString(item->name + QStringLiteral(" ")
+ item->genericName
+ QStringLiteral(" ")
+ item->comment);
default: default:
return QVariant(); return QVariant();
} }
@ -154,9 +153,9 @@ void LauncherModel::search(const QString &key)
void LauncherModel::sendToDock(const QString &key) void LauncherModel::sendToDock(const QString &key)
{ {
LauncherItem *app = findApplication(key); int index = findById(key);
if (app) { if (index != -1) {
QDBusMessage message = QDBusMessage::createMethodCall("org.cutefish.Dock", QDBusMessage message = QDBusMessage::createMethodCall("org.cutefish.Dock",
"/Dock", "/Dock",
"org.cutefish.Dock", "org.cutefish.Dock",
@ -168,9 +167,9 @@ void LauncherModel::sendToDock(const QString &key)
void LauncherModel::removeFromDock(const QString &desktop) void LauncherModel::removeFromDock(const QString &desktop)
{ {
LauncherItem *app = findApplication(desktop); int index = findById(desktop);
if (app) { if (index != -1) {
QDBusMessage message = QDBusMessage::createMethodCall("org.cutefish.Dock", QDBusMessage message = QDBusMessage::createMethodCall("org.cutefish.Dock",
"/Dock", "/Dock",
"org.cutefish.Dock", "org.cutefish.Dock",
@ -180,14 +179,14 @@ void LauncherModel::removeFromDock(const QString &desktop)
} }
} }
LauncherItem *LauncherModel::findApplication(const QString &appId) int LauncherModel::findById(const QString &id)
{ {
for (LauncherItem *item : qAsConst(m_items)) { for (int i = 0; i < m_items.size(); ++i) {
if (item->id == appId) if (m_items.at(i)->id == id)
return item; return i;
} }
return nullptr; return -1;
} }
void LauncherModel::refresh(LauncherModel *manager) void LauncherModel::refresh(LauncherModel *manager)
@ -214,40 +213,13 @@ void LauncherModel::refresh(LauncherModel *manager)
for (LauncherItem *item : qAsConst(manager->m_items)) { for (LauncherItem *item : qAsConst(manager->m_items)) {
if (!allEntries.contains(item->id)) if (!allEntries.contains(item->id))
QMetaObject::invokeMethod(manager, "removeApp", Q_ARG(QObject*, qobject_cast<QObject*>(item))); QMetaObject::invokeMethod(manager, "removeApp", Q_ARG(LauncherItem *, item));
} }
// Signal the model was refreshed // Signal the model was refreshed
QMetaObject::invokeMethod(manager, "refreshed"); QMetaObject::invokeMethod(manager, "refreshed");
} }
LauncherItem *LauncherModel::get(int index) const
{
if (index < 0 || index >= m_items.size())
return nullptr;
return m_items.at(index);
}
QString LauncherModel::getIconName(const QString &appId)
{
LauncherItem *item = get(indexFromAppId(appId));
if (item)
return item->iconName;
return QString();
}
int LauncherModel::indexFromAppId(const QString &appId) const
{
for (int i = 0; i < m_items.size(); i++) {
if (m_items.at(i)->id == appId)
return i;
}
return -1;
}
void LauncherModel::move(int from, int to, int page, int pageCount) void LauncherModel::move(int from, int to, int page, int pageCount)
{ {
if (from == to) if (from == to)
@ -266,11 +238,21 @@ void LauncherModel::move(int from, int to, int page, int pageCount)
// endMoveRows(); // endMoveRows();
} }
void LauncherModel::save()
{
QByteArray datas;
QDataStream out(&datas, QIODevice::WriteOnly);
out << m_items;
m_settings.setValue("list", datas);
}
bool LauncherModel::launch(const QString &path) bool LauncherModel::launch(const QString &path)
{ {
LauncherItem *app = findApplication(path); int index = findById(path);
if (app) {
QStringList args = app->args; if (index != -1) {
LauncherItem *item = m_items.at(index);
QStringList args = item->args;
QScopedPointer<QProcess> p(new QProcess); QScopedPointer<QProcess> p(new QProcess);
p->setStandardInputFile(QProcess::nullDevice()); p->setStandardInputFile(QProcess::nullDevice());
p->setProcessChannelMode(QProcess::ForwardedChannels); p->setProcessChannelMode(QProcess::ForwardedChannels);
@ -295,7 +277,7 @@ bool LauncherModel::launch(const QString &path)
void LauncherModel::addApp(const QString &fileName) void LauncherModel::addApp(const QString &fileName)
{ {
if (findApplication(fileName)) if (findById(fileName) != -1)
return; return;
DesktopProperties desktop(fileName, "Desktop Entry"); DesktopProperties desktop(fileName, "Desktop Entry");
@ -337,16 +319,12 @@ void LauncherModel::addApp(const QString &fileName)
beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); beginInsertRows(QModelIndex(), m_items.count(), m_items.count());
m_items.append(item); m_items.append(item);
qDebug() << "added: " << item->name; qDebug() << "added: " << item->name;
Q_EMIT applicationAdded(item); // Q_EMIT applicationAdded(item);
endInsertRows(); endInsertRows();
} }
void LauncherModel::removeApp(QObject *object) void LauncherModel::removeApp(LauncherItem *item)
{ {
LauncherItem *item = qobject_cast<LauncherItem *>(object);
if (!item)
return;
int index = m_items.indexOf(item); int index = m_items.indexOf(item);
if (index < 0) if (index < 0)
return; return;

@ -23,8 +23,10 @@
#include <QObject> #include <QObject>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QSettings>
#include "launcheritem.h"
class LauncherItem;
class LauncherModel : public QAbstractListModel class LauncherModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
@ -64,16 +66,12 @@ public:
Q_INVOKABLE void sendToDock(const QString &key); Q_INVOKABLE void sendToDock(const QString &key);
Q_INVOKABLE void removeFromDock(const QString &desktop); Q_INVOKABLE void removeFromDock(const QString &desktop);
LauncherItem *findApplication(const QString &appId); int findById(const QString &id);
static void refresh(LauncherModel *manager); static void refresh(LauncherModel *manager);
Q_INVOKABLE LauncherItem *get(int index) const;
Q_INVOKABLE QString getIconName(const QString &appId);
Q_INVOKABLE int indexFromAppId(const QString &appId) const;
Q_INVOKABLE void move(int from, int to, int page, int pageCount); Q_INVOKABLE void move(int from, int to, int page, int pageCount);
Q_INVOKABLE void save();
public Q_SLOTS: public Q_SLOTS:
Q_INVOKABLE bool launch(const QString &path); Q_INVOKABLE bool launch(const QString &path);
@ -88,11 +86,12 @@ Q_SIGNALS:
private Q_SLOTS: private Q_SLOTS:
void addApp(const QString &fileName); void addApp(const QString &fileName);
void removeApp(QObject *object); void removeApp(LauncherItem *item);
private: private:
QList<LauncherItem *> m_items; QList<LauncherItem *> m_items;
QList<LauncherItem *> m_searchItems; QList<LauncherItem *> m_searchItems;
QSettings m_settings;
Mode m_mode; Mode m_mode;
}; };

@ -21,6 +21,8 @@
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusInterface> #include <QDBusInterface>
#include <QPixmapCache> #include <QPixmapCache>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include "launcher.h" #include "launcher.h"
#include "launcheritem.h" #include "launcheritem.h"
@ -41,7 +43,7 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QByteArray uri = "Cutefish.Launcher"; QByteArray uri = "Cutefish.Launcher";
// qmlRegisterUncreatableType<LauncherItem>(uri, 1, 0, "LauncherItem", "cannot init application"); qRegisterMetaType<LauncherItem>("LauncherItem");
qmlRegisterType<LauncherItem>(uri, 1, 0, "LauncherItem"); qmlRegisterType<LauncherItem>(uri, 1, 0, "LauncherItem");
qmlRegisterType<LauncherModel>(uri, 1, 0, "LauncherModel"); qmlRegisterType<LauncherModel>(uri, 1, 0, "LauncherModel");
qmlRegisterType<PageModel>(uri, 1, 0, "PageModel"); qmlRegisterType<PageModel>(uri, 1, 0, "PageModel");
@ -58,14 +60,14 @@ int main(int argc, char *argv[])
// QPixmapCache::setCacheLimit(1024 * 10); // QPixmapCache::setCacheLimit(1024 * 10);
// QCommandLineParser parser; QCommandLineParser parser;
// QCommandLineOption showOption(QStringLiteral("show"), "Show Launcher"); QCommandLineOption showOption(QStringLiteral("show"), "Show Launcher");
// parser.addOption(showOption); parser.addOption(showOption);
// QCommandLineOption hideOption(QStringLiteral("hide"), "Hide Launcher"); // QCommandLineOption hideOption(QStringLiteral("hide"), "Hide Launcher");
// parser.addOption(hideOption); // parser.addOption(hideOption);
// QCommandLineOption toggleOption(QStringLiteral("toggle"), "Toggle Launcher"); // QCommandLineOption toggleOption(QStringLiteral("toggle"), "Toggle Launcher");
// parser.addOption(toggleOption); // parser.addOption(toggleOption);
// parser.process(app.arguments()); parser.process(app.arguments());
QDBusConnection dbus = QDBusConnection::sessionBus(); QDBusConnection dbus = QDBusConnection::sessionBus();
if (!dbus.registerService(DBUS_NAME)) { if (!dbus.registerService(DBUS_NAME)) {
@ -85,7 +87,8 @@ int main(int argc, char *argv[])
} }
} }
Launcher launcher; bool firstShow = parser.isSet(showOption);
Launcher launcher(firstShow);
if (!dbus.registerObject(DBUS_PATH, DBUS_INTERFACE, &launcher)) if (!dbus.registerObject(DBUS_PATH, DBUS_INTERFACE, &launcher))
return -1; return -1;

Loading…
Cancel
Save