mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
add contextual actions
fix icons
This commit is contained in:
parent
54174974b1
commit
a5c352bc06
@ -17,7 +17,10 @@
|
||||
|
||||
#include "awesome-widget.h"
|
||||
|
||||
#include <KStandardDirs>
|
||||
#include <Plasma/ToolTipManager>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
@ -53,6 +56,35 @@ AwesomeWidget::AwesomeWidget(QObject *parent, const QVariantList &args)
|
||||
|
||||
AwesomeWidget::~AwesomeWidget()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
}
|
||||
|
||||
|
||||
QList<QAction *> AwesomeWidget::contextualActions()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return contextMenu;
|
||||
}
|
||||
|
||||
|
||||
void AwesomeWidget::createActions()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
contextMenu.clear();
|
||||
contextMenu.append(new QAction(QIcon::fromTheme(QString("utilities-system-monitor")),
|
||||
i18n("Run ksysguard"), this));
|
||||
connect(contextMenu[0], SIGNAL(triggered(bool)), this, SLOT(showKsysguard()));
|
||||
contextMenu.append(new QAction(QIcon::fromTheme(QString("text-x-readme")),
|
||||
i18n("Show README"), this));
|
||||
connect(contextMenu[1], SIGNAL(triggered(bool)), this, SLOT(showReadme()));
|
||||
contextMenu.append(new QAction(QIcon::fromTheme(QString("stock-refresh")),
|
||||
i18n("Update text"), this));
|
||||
connect(contextMenu[2], SIGNAL(triggered(bool)), extsysmonEngine, SLOT(updateAllSources()));
|
||||
connect(contextMenu[2], SIGNAL(triggered(bool)), sysmonEngine, SLOT(updateAllSources()));
|
||||
connect(contextMenu[2], SIGNAL(triggered(bool)), timeEngine, SLOT(updateAllSources()));
|
||||
connect(contextMenu[2], SIGNAL(triggered(bool)), this, SLOT(updateNetworkDevice()));
|
||||
}
|
||||
|
||||
|
||||
@ -162,6 +194,7 @@ void AwesomeWidget::init()
|
||||
Plasma::ToolTipManager::self()->setContent(this, toolTip);
|
||||
|
||||
// body
|
||||
createActions();
|
||||
mainLayout = new QGraphicsLinearLayout();
|
||||
mainLayout->setContentsMargins(1, 1, 1, 1);
|
||||
mainLayout->setOrientation(Qt::Horizontal);
|
||||
@ -308,4 +341,44 @@ QStringList AwesomeWidget::getKeys()
|
||||
}
|
||||
|
||||
|
||||
void AwesomeWidget::showKsysguard()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString cmd = QString("ksysguard");
|
||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||
if (process.exitCode != 0)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||
}
|
||||
|
||||
|
||||
void AwesomeWidget::showReadme()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString kdeHome = KGlobal::dirs()->localkdedir();
|
||||
QString dirPath;
|
||||
if (QDir(QString("/usr/share/awesome-widgets")).exists())
|
||||
dirPath = QString("/usr/share/awesome-widgets");
|
||||
else if (QDir(kdeHome + QString("/share/awesome-widgets")).exists())
|
||||
dirPath = kdeHome + QString("/share/awesome-widgets");
|
||||
else return;
|
||||
QString locale = QLocale::system().name();
|
||||
QString filePath;
|
||||
if (QFileInfo(dirPath + locale + QString(".html")).exists())
|
||||
filePath = dirPath + locale + QString(".html");
|
||||
else {
|
||||
locale = locale.split(QChar('_'))[0];
|
||||
if (QFileInfo(dirPath + locale + QString(".html")).exists())
|
||||
filePath = dirPath + locale + QString(".html");
|
||||
else if (QFileInfo(dirPath + QString("en.html")).exists())
|
||||
filePath = dirPath + QString("en.html");
|
||||
else return;
|
||||
}
|
||||
QDesktopServices::openUrl(filePath);
|
||||
}
|
||||
|
||||
|
||||
K_EXPORT_PLASMA_APPLET(ptm-awesome-widget, AwesomeWidget)
|
||||
|
@ -52,6 +52,9 @@ public:
|
||||
QMap<QString, QString> updateDataEngineConfiguration(const QMap<QString, QString> rawConfig);
|
||||
|
||||
public slots:
|
||||
// contextual actions
|
||||
void showKsysguard();
|
||||
void showReadme();
|
||||
// dataengine
|
||||
void addDiskDevice(const QString source);
|
||||
void connectToEngine();
|
||||
@ -61,6 +64,7 @@ public slots:
|
||||
void configAccepted();
|
||||
void configChanged();
|
||||
// update events
|
||||
void updateNetworkDevice();
|
||||
void updateText(bool clear = false);
|
||||
void updateTooltip();
|
||||
|
||||
@ -77,10 +81,12 @@ private slots:
|
||||
void editTempItem(QListWidgetItem *item);
|
||||
|
||||
protected:
|
||||
QList<QAction *> contextualActions();
|
||||
void createConfigurationInterface(KConfigDialog *parent);
|
||||
|
||||
private:
|
||||
// functions
|
||||
void createActions();
|
||||
void initValues();
|
||||
QStringList findKeys();
|
||||
QStringList getKeys();
|
||||
@ -88,6 +94,7 @@ private:
|
||||
QGraphicsLinearLayout *mainLayout;
|
||||
CustomLabel *textLabel;
|
||||
QTimer *timer;
|
||||
QList<QAction *> contextMenu;
|
||||
// tooltip
|
||||
Plasma::ToolTipContent toolTip;
|
||||
QGraphicsScene *toolTipScene;
|
||||
|
@ -620,7 +620,7 @@ void AwesomeWidget::contextMenuCustomCommand(const QPoint pos)
|
||||
if (uiDEConfig.tableWidget_customCommand->currentItem() == 0) return;
|
||||
|
||||
QMenu menu(uiDEConfig.tableWidget_customCommand);
|
||||
QAction *remove = menu.addAction(QIcon("edit-delete"), i18n("Remove"));
|
||||
QAction *remove = menu.addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"));
|
||||
QAction *action = menu.exec(uiDEConfig.tableWidget_customCommand->viewport()->mapToGlobal(pos));
|
||||
if (action == remove)
|
||||
uiDEConfig.tableWidget_customCommand->removeRow(
|
||||
@ -634,7 +634,7 @@ void AwesomeWidget::contextMenuPkgCommand(const QPoint pos)
|
||||
if (uiDEConfig.tableWidget_pkgCommand->currentItem() == 0) return;
|
||||
|
||||
QMenu menu(uiDEConfig.tableWidget_pkgCommand);
|
||||
QAction *remove = menu.addAction(QIcon("edit-delete"), i18n("Remove"));
|
||||
QAction *remove = menu.addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"));
|
||||
QAction *action = menu.exec(uiDEConfig.tableWidget_pkgCommand->viewport()->mapToGlobal(pos));
|
||||
if (action == remove)
|
||||
uiDEConfig.tableWidget_pkgCommand->removeRow(
|
||||
|
@ -65,6 +65,14 @@ void AwesomeWidget::reinit()
|
||||
}
|
||||
|
||||
|
||||
void AwesomeWidget::updateNetworkDevice()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
values[QString("netdev")] = getNetworkDevice();
|
||||
}
|
||||
|
||||
|
||||
void AwesomeWidget::updateText(bool clear)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
Loading…
Reference in New Issue
Block a user