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

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

@ -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

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

@ -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
}
}
}

@ -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()
}
}
}

@ -30,7 +30,7 @@
#include <KWindowSystem>
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()

@ -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;

@ -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;
}

@ -21,17 +21,22 @@
#define LAUNCHERITEM_H
#include <QObject>
#include <QDataStream>
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

@ -19,7 +19,6 @@
#include "launchermodel.h"
#include "desktopproperties.h"
#include "launcheritem.h"
#include <QDBusInterface>
#include <QDBusPendingCallWatcher>
@ -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<QObject*>(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<QProcess> 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<LauncherItem *>(object);
if (!item)
return;
int index = m_items.indexOf(item);
if (index < 0)
return;

@ -23,8 +23,10 @@
#include <QObject>
#include <QLoggingCategory>
#include <QAbstractListModel>
#include <QSettings>
#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<LauncherItem *> m_items;
QList<LauncherItem *> m_searchItems;
QSettings m_settings;
Mode m_mode;
};

@ -21,6 +21,8 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QPixmapCache>
#include <QCommandLineOption>
#include <QCommandLineParser>
#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<LauncherItem>(uri, 1, 0, "LauncherItem", "cannot init application");
qRegisterMetaType<LauncherItem>("LauncherItem");
qmlRegisterType<LauncherItem>(uri, 1, 0, "LauncherItem");
qmlRegisterType<LauncherModel>(uri, 1, 0, "LauncherModel");
qmlRegisterType<PageModel>(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;

Loading…
Cancel
Save