mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
create initialization skeleton
This commit is contained in:
parent
b55d453aeb
commit
7cd80e14a7
@ -18,8 +18,11 @@
|
||||
#include "awesome-widget.h"
|
||||
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QNetworkInterface>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QTimer>
|
||||
|
||||
#include "customlabel.h"
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
|
||||
@ -46,6 +49,25 @@ AwesomeWidget::~AwesomeWidget()
|
||||
}
|
||||
|
||||
|
||||
QString AwesomeWidget::getNetworkDevice()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString device = QString("lo");
|
||||
if (configuration[QString("useCustomNetdev")].toInt() == 2)
|
||||
device = configuration[QString("customNetdev")];
|
||||
else {
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (int i=0; i<rawInterfaceList.count(); i++)
|
||||
if ((rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsUp)) &&
|
||||
(rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsLoopBack)))
|
||||
device = rawInterfaceList[i].name();
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
void AwesomeWidget::init()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -54,12 +76,20 @@ void AwesomeWidget::init()
|
||||
sysmonEngine = dataEngine(QString("systemmonitor"));
|
||||
timeEngine = dataEngine(QString("time"));
|
||||
|
||||
layout = new QGraphicsLinearLayout();
|
||||
layout->setContentsMargins(1, 1, 1, 1);
|
||||
setLayout(layout);
|
||||
mainLayout = new QGraphicsLinearLayout();
|
||||
mainLayout->setContentsMargins(1, 1, 1, 1);
|
||||
setLayout(mainLayout);
|
||||
|
||||
textLabel = new CustomLabel(this, debug);
|
||||
|
||||
// read variables
|
||||
configChanged();
|
||||
timer = new QTimer(this);
|
||||
timer->setSingleShot(false);
|
||||
timer->setInterval(configuration[QString("interval")].toInt());
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(updateText()));
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(updateTooltip()));
|
||||
timer->start();
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/DataEngine>
|
||||
#include <Plasma/Label>
|
||||
|
||||
#include <ui_advanced.h>
|
||||
#include <ui_appearance.h>
|
||||
@ -30,6 +29,7 @@
|
||||
#include <ui_widget.h>
|
||||
|
||||
|
||||
class CustomLabel;
|
||||
class QGraphicsLinearLayout;
|
||||
|
||||
class AwesomeWidget : public Plasma::Applet
|
||||
@ -54,6 +54,9 @@ public slots:
|
||||
// configuration interface
|
||||
void configAccepted();
|
||||
void configChanged();
|
||||
// update events
|
||||
void updateText();
|
||||
void updateTooltip();
|
||||
|
||||
private slots:
|
||||
void reinit();
|
||||
@ -64,9 +67,12 @@ protected:
|
||||
|
||||
private:
|
||||
// functions
|
||||
void updateText();
|
||||
QTimer *timer;
|
||||
// ui
|
||||
QGraphicsLinearLayout *layout;
|
||||
QGraphicsLinearLayout *mainLayout;
|
||||
CustomLabel *textLabel;
|
||||
// values
|
||||
QMap<QString, QString> values;
|
||||
// debug
|
||||
bool debug;
|
||||
// data engine
|
||||
@ -81,8 +87,7 @@ private:
|
||||
Ui::TooltipWindow uiTooltipConfig;
|
||||
// configuration
|
||||
QMap<QString, QString> configuration;
|
||||
QStringList diskDevices;
|
||||
QStringList formatLine;
|
||||
QStringList diskDevices, keys, formatLine, foundKeys;
|
||||
};
|
||||
|
||||
|
||||
|
56
sources/awesome-widget/customlabel.cpp
Normal file
56
sources/awesome-widget/customlabel.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/***************************************************************************
|
||||
* This file is part of pytextmonitor *
|
||||
* *
|
||||
* pytextmonitor is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* pytextmonitor is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with pytextmonitor. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "customlabel.h"
|
||||
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
#include "awesome-widget.h"
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
|
||||
CustomLabel::CustomLabel(AwesomeWidget *wid, const bool debugCmd)
|
||||
: Plasma::Label(wid),
|
||||
debug(debugCmd)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CustomLabel::~CustomLabel()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
}
|
||||
|
||||
|
||||
void CustomLabel::setPopupEnabled(const bool state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << state;
|
||||
|
||||
enablePopup = state;
|
||||
}
|
||||
|
||||
|
||||
void CustomLabel::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Get signal" << event->button();
|
||||
|
||||
if ((enablePopup) && (event->button() == Qt::LeftButton))
|
||||
{}
|
||||
emit(Plasma::Label::mousePressEvent(event));
|
||||
}
|
44
sources/awesome-widget/customlabel.h
Normal file
44
sources/awesome-widget/customlabel.h
Normal file
@ -0,0 +1,44 @@
|
||||
/***************************************************************************
|
||||
* This file is part of pytextmonitor *
|
||||
* *
|
||||
* pytextmonitor is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* pytextmonitor is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with pytextmonitor. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CUSTOMLABEL_H
|
||||
#define CUSTOMLABEL_H
|
||||
|
||||
#include <Plasma/Label>
|
||||
|
||||
|
||||
class AwesomeWidget;
|
||||
|
||||
class CustomLabel : public Plasma::Label
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CustomLabel(AwesomeWidget *wid, const bool debugCmd);
|
||||
~CustomLabel();
|
||||
void setPopupEnabled(const bool state);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
bool debug;
|
||||
bool enablePopup;
|
||||
};
|
||||
|
||||
|
||||
#endif /* CUSTOMLABEL_H */
|
@ -17,13 +17,41 @@
|
||||
|
||||
#include "awesome-widget.h"
|
||||
|
||||
#include <QGraphicsLinearLayout>
|
||||
//#include <QThread>
|
||||
|
||||
#include "customlabel.h"
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
|
||||
void AwesomeWidget::reinit()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
mainLayout = new QGraphicsLinearLayout();
|
||||
mainLayout->setContentsMargins(1, 1, 1, 1);
|
||||
setLayout(mainLayout);
|
||||
|
||||
if (configuration[QString("background")].toInt() == 0)
|
||||
setBackgroundHints(NoBackground);
|
||||
else
|
||||
setBackgroundHints(DefaultBackground);
|
||||
if (configuration[QString("layout")].toInt() == 0)
|
||||
mainLayout->setOrientation(Qt::Horizontal);
|
||||
else
|
||||
mainLayout->setOrientation(Qt::Vertical);
|
||||
if (configuration[QString("leftStretch")].toInt() == 2)
|
||||
mainLayout->addStretch(1);
|
||||
if (configuration[QString("popup")].toInt() == 0)
|
||||
textLabel->setPopupEnabled(true);
|
||||
mainLayout->addItem(textLabel);
|
||||
if (configuration[QString("rightStretch")].toInt() == 2)
|
||||
mainLayout->addStretch(1);
|
||||
|
||||
values[QString("netdev")] = getNetworkDevice();
|
||||
// thread()->wait(60000);
|
||||
connectToEngine();
|
||||
resize(10, 10);
|
||||
}
|
||||
|
||||
|
||||
@ -31,3 +59,9 @@ void AwesomeWidget::updateText()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
}
|
||||
|
||||
|
||||
void AwesomeWidget::updateTooltip()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user