add abstactextitem class (building is broken atm)

This commit is contained in:
arcan1s
2015-07-23 00:07:21 +03:00
parent b699095f38
commit 880a986782
13 changed files with 437 additions and 855 deletions

View File

@ -22,7 +22,6 @@
#include <QDir>
#include <QSettings>
#include <QTextCodec>
#include <QTime>
#include <pdebug/pdebug.h>
@ -31,20 +30,18 @@
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
const QStringList directories, const bool debugCmd)
: QDialog(parent),
m_fileName(upgradeName),
m_dirs(directories),
: AbstractExtItem(parent, upgradeName, directories, debugCmd),
debug(debugCmd),
ui(new Ui::ExtUpgrade)
{
m_name = m_fileName;
readConfiguration();
// init process
ui->setupUi(this);
value[QString("value")] = 0;
process = new QProcess(this);
connect(process, SIGNAL(finished(int)), this, SLOT(updateValue()));
process->waitForFinished(0);
// init ui
ui->setupUi(this);
}
@ -58,22 +55,6 @@ ExtUpgrade::~ExtUpgrade()
}
int ExtUpgrade::apiVersion()
{
if (debug) qDebug() << PDEBUG;
return m_apiVersion;
}
QString ExtUpgrade::comment()
{
if (debug) qDebug() << PDEBUG;
return m_comment;
}
QString ExtUpgrade::executable()
{
if (debug) qDebug() << PDEBUG;
@ -82,30 +63,6 @@ QString ExtUpgrade::executable()
}
QString ExtUpgrade::fileName()
{
if (debug) qDebug() << PDEBUG;
return m_fileName;
}
int ExtUpgrade::interval()
{
if (debug) qDebug() << PDEBUG;
return m_interval;
}
QString ExtUpgrade::name()
{
if (debug) qDebug() << PDEBUG;
return m_name;
}
int ExtUpgrade::null()
{
if (debug) qDebug() << PDEBUG;
@ -114,57 +71,6 @@ int ExtUpgrade::null()
}
int ExtUpgrade::number()
{
if (debug) qDebug() << PDEBUG;
return m_number;
}
QString ExtUpgrade::tag()
{
if (debug) qDebug() << PDEBUG;
return QString("pkgcount%1").arg(m_number);
}
bool ExtUpgrade::isActive()
{
if (debug) qDebug() << PDEBUG;
return m_active;
}
void ExtUpgrade::setApiVersion(const int _apiVersion)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
m_apiVersion = _apiVersion;
}
void ExtUpgrade::setActive(const bool _state)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
m_active = _state;
}
void ExtUpgrade::setComment(const QString _comment)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
m_comment = _comment;
}
void ExtUpgrade::setExecutable(const QString _executable)
{
if (debug) qDebug() << PDEBUG;
@ -174,24 +80,6 @@ void ExtUpgrade::setExecutable(const QString _executable)
}
void ExtUpgrade::setInterval(const int _interval)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
m_interval = _interval;
}
void ExtUpgrade::setName(const QString _name)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
m_name = _name;
}
void ExtUpgrade::setNull(const int _null)
{
if (debug) qDebug() << PDEBUG;
@ -202,58 +90,36 @@ void ExtUpgrade::setNull(const int _null)
}
void ExtUpgrade::setNumber(int _number)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Number" << _number;
if (_number == -1) {
if (debug) qDebug() << PDEBUG << ":" << "Number is empty, generate new one";
qsrand(QTime::currentTime().msec());
_number = qrand() % 1000;
if (debug) qDebug() << PDEBUG << ":" << "Generated number is" << _number;
}
m_number = _number;
}
void ExtUpgrade::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
for (int i=m_dirs.count()-1; i>=0; i--) {
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
for (int i=directories().count()-1; i>=0; i--) {
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setName(settings.value(QString("Name"), m_name).toString());
setComment(settings.value(QString("Comment"), m_comment).toString());
setApiVersion(settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
setExecutable(settings.value(QString("Exec"), m_executable).toString());
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
setNull(settings.value(QString("X-AW-Null"), m_null).toInt());
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
// api == 2
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
settings.endGroup();
}
// update for current API
if ((m_apiVersion > 0) && (m_apiVersion < AWEUAPI)) {
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
setApiVersion(AWEUAPI);
writeConfiguration();
}
}
int ExtUpgrade::run()
QVariantMap ExtUpgrade::run()
{
if (debug) qDebug() << PDEBUG;
if (!m_active) return value;
if (!isActive()) return value;
if ((times == 1) && (process->state() == QProcess::NotRunning))
process->start(QString("sh -c \"%1\"").arg(m_executable));
else if (times >= m_interval)
else if (times >= interval())
times = 0;
times++;
@ -265,13 +131,13 @@ int ExtUpgrade::showConfiguration()
{
if (debug) qDebug() << PDEBUG;
ui->lineEdit_name->setText(m_name);
ui->lineEdit_comment->setText(m_comment);
ui->label_numberValue->setText(QString("%1").arg(m_number));
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_command->setText(m_executable);
ui->checkBox_active->setCheckState(m_active ? Qt::Checked : Qt::Unchecked);
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->spinBox_null->setValue(m_null);
ui->spinBox_interval->setValue(m_interval);
ui->spinBox_interval->setValue(interval());
int ret = exec();
if (ret != 1) return ret;
@ -289,38 +155,16 @@ int ExtUpgrade::showConfiguration()
}
bool ExtUpgrade::tryDelete()
{
if (debug) qDebug() << PDEBUG;
for (int i=0; i<m_dirs.count(); i++)
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
// check if exists
for (int i=0; i<m_dirs.count(); i++)
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
return true;
}
void ExtUpgrade::writeConfiguration()
{
if (debug) qDebug() << PDEBUG;
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Encoding"), QString("UTF-8"));
settings.setValue(QString("Name"), m_name);
settings.setValue(QString("Comment"), m_comment);
settings.setValue(QString("Exec"), m_executable);
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
settings.setValue(QString("X-AW-Null"), m_null);
settings.setValue(QString("X-AW-Interval"), m_interval);
settings.setValue(QString("X-AW-Number"), m_number);
settings.endGroup();
settings.sync();
@ -335,5 +179,5 @@ void ExtUpgrade::updateValue()
if (debug) qDebug() << PDEBUG << ":" << "Error" << process->readAllStandardError();
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
value = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count() - m_null;
value[QString("value")] = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count() - m_null;
}