Add send to desktop option

pull/16/head
kateleet 5 years ago
parent 27d59ea8bf
commit aa5f787ac7

@ -122,6 +122,12 @@ Item {
onTriggered: launcherModel.sendToDock(model.appId)
}
MenuItem {
id: sendToDesktop
text: qsTr("Send to desktop")
onTriggered: launcherModel.sendToDesktop(model.appId)
}
MenuItem {
id: removeFromDock
text: qsTr("Remove from dock")
@ -178,6 +184,24 @@ Item {
text: label.text
}
Rectangle {
id: newInstallPoint
width: 6
height: 6
visible: model.newInstalled
anchors {
horizontalCenter: parent.horizontalCenter
bottom: label.top
bottomMargin: FishUI.Units.smallSpacing
}
color: FishUI.Theme.highlightColor
radius: height / 2
}
Label {
id: label

@ -20,6 +20,7 @@
#include "appitem.h"
AppItem::AppItem()
: newInstalled(false)
{
}
@ -31,6 +32,7 @@ AppItem::AppItem(const AppItem &info)
, comment(info.comment)
, iconName(info.iconName)
, args(info.args)
, newInstalled(false)
{
}

@ -41,6 +41,8 @@ public:
QString comment;
QString iconName;
QStringList args;
bool newInstalled;
};
Q_DECLARE_METATYPE(AppItem)

@ -27,6 +27,7 @@
#include <QtConcurrent/QtConcurrentRun>
#include <QRegularExpression>
#include <QFileSystemWatcher>
#include <QStandardPaths>
#include <QScopedPointer>
#include <QDirIterator>
#include <QDebug>
@ -47,7 +48,7 @@ LauncherModel::LauncherModel(QObject *parent)
: QAbstractListModel(parent)
, m_settings("cutefishos", "launcher-applist", this)
, m_mode(NormalMode)
, m_needSort(false)
, m_firstLoad(false)
{
// Init datas.
QByteArray listByteArray = m_settings.value("list").toByteArray();
@ -55,7 +56,7 @@ LauncherModel::LauncherModel(QObject *parent)
in >> m_appItems;
if (m_appItems.isEmpty())
m_needSort = true;
m_firstLoad = true;
QtConcurrent::run(LauncherModel::refresh, this);
@ -66,6 +67,7 @@ LauncherModel::LauncherModel(QObject *parent)
});
m_saveTimer.setInterval(1000);
m_saveTimer.setSingleShot(true);
connect(&m_saveTimer, &QTimer::timeout, this, &LauncherModel::save);
connect(this, &QAbstractItemModel::rowsInserted, this, &LauncherModel::countChanged);
@ -77,6 +79,7 @@ LauncherModel::LauncherModel(QObject *parent)
LauncherModel::~LauncherModel()
{
LauncherModel::save();
}
int LauncherModel::count() const
@ -96,17 +99,22 @@ int LauncherModel::rowCount(const QModelIndex &parent) const
QHash<int, QByteArray> LauncherModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles.insert(AppIdRole, "appId");
roles.insert(ApplicationRole, "application");
roles.insert(NameRole, "name");
roles.insert(GenericNameRole, "genericName");
roles.insert(CommentRole, "comment");
roles.insert(IconNameRole, "iconName");
roles.insert(CategoriesRole, "categories");
roles.insert(FilterInfoRole, "filterInfo");
roles.insert(PinnedRole, "pinned");
roles.insert(PinnedIndexRole, "pinnedIndex");
static QHash<int, QByteArray> roles;
if (roles.isEmpty()) {
roles.insert(AppIdRole, "appId");
roles.insert(ApplicationRole, "application");
roles.insert(NameRole, "name");
roles.insert(GenericNameRole, "genericName");
roles.insert(CommentRole, "comment");
roles.insert(IconNameRole, "iconName");
roles.insert(CategoriesRole, "categories");
roles.insert(FilterInfoRole, "filterInfo");
roles.insert(PinnedRole, "pinned");
roles.insert(PinnedIndexRole, "pinnedIndex");
roles.insert(NewInstalledRole, "newInstalled");
}
return roles;
}
@ -130,9 +138,11 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
+ appItem.genericName
+ QStringLiteral(" ")
+ appItem.comment);
default:
return QVariant();
case NewInstalledRole:
return appItem.newInstalled;
}
return QVariant();
}
void LauncherModel::search(const QString &key)
@ -168,6 +178,20 @@ void LauncherModel::sendToDock(const QString &key)
}
}
void LauncherModel::sendToDesktop(const QString &key)
{
int index = findById(key);
if (index != -1) {
QFileInfo info(key);
QString newFileName = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
newFileName.append(QString("/%1").arg(info.fileName()));
QFile::copy(key, newFileName);
}
}
void LauncherModel::removeFromDock(const QString &desktop)
{
int index = findById(desktop);
@ -264,10 +288,16 @@ bool LauncherModel::launch(const QString &path)
int index = findById(path);
if (index != -1) {
const AppItem &item = m_appItems.at(index);
AppItem &item = m_appItems[index];
QStringList args = item.args;
QString cmd = args.takeFirst();
if (item.newInstalled) {
item.newInstalled = false;
emit dataChanged(LauncherModel::index(index), LauncherModel::index(index));
delaySave();
}
// Because launcher has hidden animation,
// cutefish-screenshot needs to be processed.
if (cmd == "cutefish-screenshot") {
@ -286,10 +316,10 @@ bool LauncherModel::launch(const QString &path)
void LauncherModel::onRefreshed()
{
if (!m_needSort)
if (!m_firstLoad)
return;
m_needSort = false;
m_firstLoad = false;
beginResetModel();
std::sort(m_appItems.begin(), m_appItems.end(), [=] (AppItem &a, AppItem &b) {
@ -349,14 +379,16 @@ void LauncherModel::addApp(const QString &fileName)
appItem.comment = desktop.value("Comment").toString();
appItem.iconName = desktop.value("Icon").toString();
appItem.args = appExec.split(" ");
appItem.newInstalled = true;
beginInsertRows(QModelIndex(), m_appItems.count(), m_appItems.count());
m_appItems.append(appItem);
qDebug() << "added: " << appItem.name;
endInsertRows();
if (!m_needSort)
if (!m_firstLoad) {
delaySave();
}
}
}

@ -44,7 +44,8 @@ public:
CategoriesRole,
FilterInfoRole,
PinnedRole,
PinnedIndexRole
PinnedIndexRole,
NewInstalledRole
};
Q_ENUM(Roles)
@ -64,6 +65,7 @@ public:
Q_INVOKABLE void search(const QString &key);
Q_INVOKABLE void sendToDock(const QString &key);
Q_INVOKABLE void sendToDesktop(const QString &key);
Q_INVOKABLE void removeFromDock(const QString &desktop);
int findById(const QString &id);
@ -97,7 +99,7 @@ private:
QSettings m_settings;
Mode m_mode;
bool m_needSort;
bool m_firstLoad;
};
#endif // LAUNCHERMODEL_H

@ -20,6 +20,7 @@
#include "processprovider.h"
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QProcess>
ProcessProvider::ProcessProvider(QObject *parent)
: QObject(parent)
@ -36,6 +37,9 @@ bool ProcessProvider::startDetached(const QString &exec, QStringList args)
if (iface.isValid()) {
iface.asyncCall("launch", exec, args).waitForFinished();
return true;
} else {
QProcess process;
process.startDetached(exec, args);
}
return false;

@ -4,17 +4,22 @@
<context>
<name>GridItemDelegate</name>
<message>
<location filename="../qml/GridItemDelegate.qml" line="99"/>
<location filename="../qml/GridItemDelegate.qml" line="115"/>
<source>Open</source>
<translation type="unfinished">Open</translation>
</message>
<message>
<location filename="../qml/GridItemDelegate.qml" line="105"/>
<location filename="../qml/GridItemDelegate.qml" line="121"/>
<source>Send to dock</source>
<translation>Send to dock</translation>
</message>
<message>
<location filename="../qml/GridItemDelegate.qml" line="111"/>
<location filename="../qml/GridItemDelegate.qml" line="127"/>
<source>Send to desktop</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/GridItemDelegate.qml" line="133"/>
<source>Remove from dock</source>
<translation>Remove from dock</translation>
</message>
@ -22,7 +27,7 @@
<context>
<name>Launcher</name>
<message>
<location filename="../src/launcher.cpp" line="56"/>
<location filename="../src/launcher.cpp" line="57"/>
<source>Launcher</source>
<translation>Launcher</translation>
</message>
@ -30,12 +35,12 @@
<context>
<name>main</name>
<message>
<location filename="../qml/main.qml" line="218"/>
<location filename="../qml/main.qml" line="213"/>
<source>Search</source>
<translation>Search</translation>
</message>
<message>
<location filename="../qml/main.qml" line="293"/>
<location filename="../qml/main.qml" line="288"/>
<source>Not found</source>
<translation>Not found</translation>
</message>

@ -4,25 +4,30 @@
<context>
<name>GridItemDelegate</name>
<message>
<location filename="../qml/GridItemDelegate.qml" line="99"/>
<location filename="../qml/GridItemDelegate.qml" line="115"/>
<source>Open</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../qml/GridItemDelegate.qml" line="105"/>
<location filename="../qml/GridItemDelegate.qml" line="121"/>
<source>Send to dock</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../qml/GridItemDelegate.qml" line="111"/>
<location filename="../qml/GridItemDelegate.qml" line="127"/>
<source>Send to desktop</source>
<translation></translation>
</message>
<message>
<location filename="../qml/GridItemDelegate.qml" line="133"/>
<source>Remove from dock</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
</context>
<context>
<name>Launcher</name>
<message>
<location filename="../src/launcher.cpp" line="56"/>
<location filename="../src/launcher.cpp" line="57"/>
<source>Launcher</source>
<translation></translation>
</message>
@ -30,12 +35,12 @@
<context>
<name>main</name>
<message>
<location filename="../qml/main.qml" line="218"/>
<location filename="../qml/main.qml" line="213"/>
<source>Search</source>
<translation></translation>
</message>
<message>
<location filename="../qml/main.qml" line="293"/>
<location filename="../qml/main.qml" line="288"/>
<source>Not found</source>
<translation></translation>
</message>

Loading…
Cancel
Save