/*************************************************************************** * This file is part of awesome-widgets * * * * awesome-widgets 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. * * * * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ #include "abstractextitem.h" #include #include #include #include #include #include #include "version.h" AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName, const QStringList directories, const bool debugCmd) : QDialog(parent), m_fileName(desktopName), m_dirs(directories), debug(debugCmd) { m_name = m_fileName; } AbstractExtItem::~AbstractExtItem() { if (debug) qDebug() << PDEBUG; } int AbstractExtItem::apiVersion() const { if (debug) qDebug() << PDEBUG; return m_apiVersion; } QString AbstractExtItem::comment() const { if (debug) qDebug() << PDEBUG; return m_comment; } QStringList AbstractExtItem::directories() const { if (debug) qDebug() << PDEBUG; return m_dirs; } QString AbstractExtItem::fileName() const { if (debug) qDebug() << PDEBUG; return m_fileName; } int AbstractExtItem::interval() const { if (debug) qDebug() << PDEBUG; return m_interval; } bool AbstractExtItem::isActive() const { if (debug) qDebug() << PDEBUG; return m_active; } QString AbstractExtItem::name() const { if (debug) qDebug() << PDEBUG; return m_name; } int AbstractExtItem::number() const { if (debug) qDebug() << PDEBUG; return m_number; } QString AbstractExtItem::tag(const QString _type) const { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Tag type" << _type; return QString("%1%2").arg(_type).arg(m_number); } void AbstractExtItem::setApiVersion(const int _apiVersion) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion; m_apiVersion = _apiVersion; } void AbstractExtItem::setActive(const bool _state) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "State" << _state; m_active = _state; } void AbstractExtItem::setComment(const QString _comment) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment; m_comment = _comment; } void AbstractExtItem::setDirectories(QStringList _directories) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Directories" << _directories; m_dirs = _directories; } void AbstractExtItem::setFileName(const QString _fileName) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Filename" << _fileName; m_fileName = _fileName; } void AbstractExtItem::setInterval(const int _interval) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval; if (_interval <= 0) return; m_interval = _interval; } void AbstractExtItem::setName(const QString _name) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Name" << _name; m_name = _name; } void AbstractExtItem::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 AbstractExtItem::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); 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()); setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true")); setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt()); setNumber(settings.value(QString("X-AW-Number"), m_number).toInt()); settings.endGroup(); } } bool AbstractExtItem::tryDelete() const { if (debug) qDebug() << PDEBUG; for (int i=0; i