diff --git a/qml.qrc b/qml.qrc index 7b2295a..46f3992 100755 --- a/qml.qrc +++ b/qml.qrc @@ -3,5 +3,6 @@ qml/main.qml qml/GridItemDelegate.qml qml/AllAppsView.qml + qml/CategoryView.qml diff --git a/qml/AllAppsView.qml b/qml/AllAppsView.qml index 3c0005b..efd1405 100644 --- a/qml/AllAppsView.qml +++ b/qml/AllAppsView.qml @@ -45,7 +45,7 @@ ListView { model: Math.ceil(control.modelCount / control.pageCount) maximumFlickVelocity: 10000 - highlightMoveDuration: 100 + highlightMoveDuration: 300 preferredHighlightBegin: 0 preferredHighlightEnd: 0 @@ -73,6 +73,11 @@ ListView { } } + DropArea { + anchors.fill: parent + z: -1 + } + MouseArea { anchors.fill: parent z: -1 diff --git a/qml/CategoryView.qml b/qml/CategoryView.qml new file mode 100644 index 0000000..9c36e13 --- /dev/null +++ b/qml/CategoryView.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/qml/GridItemDelegate.qml b/qml/GridItemDelegate.qml index af90b9a..7b8940e 100755 --- a/qml/GridItemDelegate.qml +++ b/qml/GridItemDelegate.qml @@ -35,6 +35,8 @@ Item { property int pageCount: 0 Drag.active: iconMouseArea.drag.active + Drag.mimeData: [model.appId] + Drag.keys: ["cutefish-launcher"] Drag.dragType: Drag.Automatic Drag.supportedActions: Qt.MoveAction Drag.hotSpot.x: icon.width / 2 @@ -181,5 +183,9 @@ Item { width: parent.width - 2 * FishUI.Units.smallSpacing height: fontMetrics.height * 2 color: "white" + + MouseArea { + anchors.fill: parent + } } } diff --git a/qml/main.qml b/qml/main.qml index 3881820..77c6aaa 100755 --- a/qml/main.qml +++ b/qml/main.qml @@ -307,6 +307,12 @@ Item { } } + Timer { + id: clearSearchTimer + interval: 100 + onTriggered: textField.text = "" + } + Connections { target: launcher @@ -316,7 +322,7 @@ Item { appView.focus = true appView.forceActiveFocus() } else { - textField.text = "" + clearSearchTimer.restart() } } } diff --git a/src/launcher.cpp b/src/launcher.cpp index c0f4fd6..a55a981 100644 --- a/src/launcher.cpp +++ b/src/launcher.cpp @@ -30,7 +30,7 @@ #include -Launcher::Launcher(QQuickView *w) +Launcher::Launcher(bool firstShow, QQuickView *w) : QQuickView(w) , m_dockInterface("org.cutefish.Dock", "/Dock", @@ -54,7 +54,7 @@ Launcher::Launcher(QQuickView *w) setSource(QUrl(QStringLiteral("qrc:/qml/main.qml"))); setTitle(tr("Launcher")); - setVisible(false); + setVisible(firstShow); // Let the animation in qml be hidden after the execution is complete m_hideTimer->setInterval(200); @@ -114,10 +114,9 @@ void Launcher::showWindow() void Launcher::hideWindow() { + setVisible(false); m_showed = false; emit showedChanged(); - - setVisible(false); } void Launcher::toggle() diff --git a/src/launcher.h b/src/launcher.h index e1e5b63..76bf9c2 100644 --- a/src/launcher.h +++ b/src/launcher.h @@ -36,7 +36,7 @@ class Launcher : public QQuickView Q_PROPERTY(int bottomMargin READ bottomMargin NOTIFY marginsChanged) public: - Launcher(QQuickView *w = nullptr); + Launcher(bool firstShow = false, QQuickView *w = nullptr); int leftMargin() const; int rightMargin() const; diff --git a/src/launcheritem.cpp b/src/launcheritem.cpp index e1a5400..92c6fee 100644 --- a/src/launcheritem.cpp +++ b/src/launcheritem.cpp @@ -19,8 +19,31 @@ #include "launcheritem.h" -LauncherItem::LauncherItem(QObject *parent) - : QObject(parent) +LauncherItem::LauncherItem() { } + +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; +} diff --git a/src/launcheritem.h b/src/launcheritem.h index 7cacb20..227a5e9 100644 --- a/src/launcheritem.h +++ b/src/launcheritem.h @@ -21,17 +21,22 @@ #define LAUNCHERITEM_H #include +#include class LauncherItem : public QObject { Q_OBJECT - Q_PROPERTY(QString fuke READ fuke CONSTANT) 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 name; QString genericName; @@ -40,4 +45,6 @@ public: QStringList args; }; +Q_DECLARE_METATYPE(LauncherItem) + #endif // LAUNCHERITEM_H diff --git a/src/launchermodel.cpp b/src/launchermodel.cpp index 7b0be55..b231982 100755 --- a/src/launchermodel.cpp +++ b/src/launchermodel.cpp @@ -19,7 +19,6 @@ #include "launchermodel.h" #include "desktopproperties.h" -#include "launcheritem.h" #include #include @@ -45,8 +44,9 @@ static QByteArray detectDesktopEnvironment() } LauncherModel::LauncherModel(QObject *parent) - : QAbstractListModel(parent), - m_mode(NormalMode) + : QAbstractListModel(parent) + , m_settings("cutefishos", "launcher-applist", this) + , m_mode(NormalMode) { QtConcurrent::run(LauncherModel::refresh, this); @@ -113,11 +113,7 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const return QVariant(); LauncherItem *item = m_mode == NormalMode - ? m_items.at(index.row()) - : m_searchItems.at(index.row()); - - if (!item) - return QVariant(); + ? m_items.at(index.row()) : m_searchItems.at(index.row()); switch (role) { case AppIdRole: @@ -127,7 +123,10 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const case IconNameRole: return item->iconName; case FilterInfoRole: - return QString(item->name + QStringLiteral(" ") + item->genericName + QStringLiteral(" ") + item->comment); + return QString(item->name + QStringLiteral(" ") + + item->genericName + + QStringLiteral(" ") + + item->comment); default: return QVariant(); } @@ -154,9 +153,9 @@ void LauncherModel::search(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", "/Dock", "org.cutefish.Dock", @@ -168,9 +167,9 @@ void LauncherModel::sendToDock(const QString &key) 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", "/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)) { - if (item->id == appId) - return item; + for (int i = 0; i < m_items.size(); ++i) { + if (m_items.at(i)->id == id) + return i; } - return nullptr; + return -1; } void LauncherModel::refresh(LauncherModel *manager) @@ -214,40 +213,13 @@ void LauncherModel::refresh(LauncherModel *manager) for (LauncherItem *item : qAsConst(manager->m_items)) { if (!allEntries.contains(item->id)) - QMetaObject::invokeMethod(manager, "removeApp", Q_ARG(QObject*, qobject_cast(item))); + QMetaObject::invokeMethod(manager, "removeApp", Q_ARG(LauncherItem *, item)); } // Signal the model was 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) { if (from == to) @@ -263,14 +235,24 @@ void LauncherModel::move(int from, int to, int page, int pageCount) // else // beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); -// 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) { - LauncherItem *app = findApplication(path); - if (app) { - QStringList args = app->args; + int index = findById(path); + + if (index != -1) { + LauncherItem *item = m_items.at(index); + QStringList args = item->args; QScopedPointer p(new QProcess); p->setStandardInputFile(QProcess::nullDevice()); p->setProcessChannelMode(QProcess::ForwardedChannels); @@ -295,7 +277,7 @@ bool LauncherModel::launch(const QString &path) void LauncherModel::addApp(const QString &fileName) { - if (findApplication(fileName)) + if (findById(fileName) != -1) return; DesktopProperties desktop(fileName, "Desktop Entry"); @@ -337,16 +319,12 @@ void LauncherModel::addApp(const QString &fileName) beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); m_items.append(item); qDebug() << "added: " << item->name; - Q_EMIT applicationAdded(item); + // Q_EMIT applicationAdded(item); endInsertRows(); } -void LauncherModel::removeApp(QObject *object) +void LauncherModel::removeApp(LauncherItem *item) { - LauncherItem *item = qobject_cast(object); - if (!item) - return; - int index = m_items.indexOf(item); if (index < 0) return; diff --git a/src/launchermodel.h b/src/launchermodel.h index f5b25ba..37cb901 100755 --- a/src/launchermodel.h +++ b/src/launchermodel.h @@ -23,8 +23,10 @@ #include #include #include +#include + +#include "launcheritem.h" -class LauncherItem; class LauncherModel : public QAbstractListModel { Q_OBJECT @@ -64,16 +66,12 @@ public: Q_INVOKABLE void sendToDock(const QString &key); Q_INVOKABLE void removeFromDock(const QString &desktop); - LauncherItem *findApplication(const QString &appId); + int findById(const QString &id); 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 save(); public Q_SLOTS: Q_INVOKABLE bool launch(const QString &path); @@ -88,11 +86,12 @@ Q_SIGNALS: private Q_SLOTS: void addApp(const QString &fileName); - void removeApp(QObject *object); + void removeApp(LauncherItem *item); private: QList m_items; QList m_searchItems; + QSettings m_settings; Mode m_mode; }; diff --git a/src/main.cpp b/src/main.cpp index ac21702..46efc6f 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "launcher.h" #include "launcheritem.h" @@ -41,7 +43,7 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QByteArray uri = "Cutefish.Launcher"; - // qmlRegisterUncreatableType(uri, 1, 0, "LauncherItem", "cannot init application"); + qRegisterMetaType("LauncherItem"); qmlRegisterType(uri, 1, 0, "LauncherItem"); qmlRegisterType(uri, 1, 0, "LauncherModel"); qmlRegisterType(uri, 1, 0, "PageModel"); @@ -58,14 +60,14 @@ int main(int argc, char *argv[]) // QPixmapCache::setCacheLimit(1024 * 10); - // QCommandLineParser parser; - // QCommandLineOption showOption(QStringLiteral("show"), "Show Launcher"); - // parser.addOption(showOption); + QCommandLineParser parser; + QCommandLineOption showOption(QStringLiteral("show"), "Show Launcher"); + parser.addOption(showOption); // QCommandLineOption hideOption(QStringLiteral("hide"), "Hide Launcher"); // parser.addOption(hideOption); // QCommandLineOption toggleOption(QStringLiteral("toggle"), "Toggle Launcher"); // parser.addOption(toggleOption); - // parser.process(app.arguments()); + parser.process(app.arguments()); QDBusConnection dbus = QDBusConnection::sessionBus(); 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)) return -1;