mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-11-04 06:43:41 +00:00 
			
		
		
		
	rewrite formatters according to rfc #91
This commit is contained in:
		@ -11,9 +11,11 @@ include_directories(
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
 | 
					file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
 | 
				
			||||||
 | 
					file(GLOB SUBPROJECT_UI *.ui)
 | 
				
			||||||
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
 | 
					file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE})
 | 
					qt5_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
 | 
				
			||||||
 | 
					add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER})
 | 
				
			||||||
target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
 | 
					target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
 | 
					install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										151
									
								
								sources/awesome-widget/plugin/awabstractformatter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								sources/awesome-widget/plugin/awabstractformatter.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,151 @@
 | 
				
			|||||||
 | 
					/***************************************************************************
 | 
				
			||||||
 | 
					 *   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 "awabstractformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QDir>
 | 
				
			||||||
 | 
					#include <QSettings>
 | 
				
			||||||
 | 
					#include <QStandardPaths>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "awdebug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AWAbstractFormatter::AWAbstractFormatter(QWidget *parent,
 | 
				
			||||||
 | 
					                                         const QString filePath)
 | 
				
			||||||
 | 
					    : QDialog(parent)
 | 
				
			||||||
 | 
					    , m_fileName(filePath)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    qCDebug(LOG_AW) << "Desktop name" << filePath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_name = m_fileName;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AWAbstractFormatter::~AWAbstractFormatter()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWAbstractFormatter::copyDefaults(AWAbstractFormatter *_other) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    _other->setComment(m_comment);
 | 
				
			||||||
 | 
					    _other->setName(m_name);
 | 
				
			||||||
 | 
					    _other->setType(m_type);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString AWAbstractFormatter::writtableConfig() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    QStringList paths = m_fileName.split(QChar('/'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QString name = paths.takeLast();
 | 
				
			||||||
 | 
					    QString dir = paths.takeLast();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return QString("%1/awesomewidgets/%2/%3")
 | 
				
			||||||
 | 
					        .arg(QStandardPaths::writableLocation(
 | 
				
			||||||
 | 
					            QStandardPaths::GenericDataLocation))
 | 
				
			||||||
 | 
					        .arg(dir)
 | 
				
			||||||
 | 
					        .arg(name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString AWAbstractFormatter::comment() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_comment;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString AWAbstractFormatter::fileName() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_fileName;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString AWAbstractFormatter::name() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_name;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString AWAbstractFormatter::type() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_type;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWAbstractFormatter::setComment(const QString _comment)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_AW) << "Comment" << _comment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_comment = _comment;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWAbstractFormatter::setName(const QString _name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_AW) << "Name" << _name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_name = _name;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWAbstractFormatter::setType(const QString _type)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_AW) << "Type" << _type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_type = _type;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWAbstractFormatter::readConfiguration()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    QSettings settings(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());
 | 
				
			||||||
 | 
					    setType(settings.value(QString("Type"), m_type).toString());
 | 
				
			||||||
 | 
					    settings.endGroup();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool AWAbstractFormatter::tryDelete() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    bool status = QFile::remove(m_fileName);
 | 
				
			||||||
 | 
					    qCInfo(LOG_AW) << "Remove file" << m_fileName << status;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return status;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWAbstractFormatter::writeConfiguration() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    QSettings settings(writtableConfig(), QSettings::IniFormat);
 | 
				
			||||||
 | 
					    qCInfo(LOG_AW) << "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("Type"), m_type);
 | 
				
			||||||
 | 
					    settings.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.sync();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -18,19 +18,48 @@
 | 
				
			|||||||
#ifndef AWABSTRACTFORMATTER_H
 | 
					#ifndef AWABSTRACTFORMATTER_H
 | 
				
			||||||
#define AWABSTRACTFORMATTER_H
 | 
					#define AWABSTRACTFORMATTER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QObject>
 | 
					#include <QDialog>
 | 
				
			||||||
#include <QVariant>
 | 
					#include <QVariant>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AWAbstractFormatter : public QObject
 | 
					class AWAbstractFormatter : public QDialog
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    Q_OBJECT
 | 
				
			||||||
 | 
					    Q_PROPERTY(QString comment READ comment WRITE setComment)
 | 
				
			||||||
 | 
					    Q_PROPERTY(QString fileName READ fileName)
 | 
				
			||||||
 | 
					    Q_PROPERTY(QString name READ name WRITE setName)
 | 
				
			||||||
 | 
					    Q_PROPERTY(QString type READ type WRITE setType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    explicit AWAbstractFormatter(QObject *parent, const QString, const QString)
 | 
					    explicit AWAbstractFormatter(QWidget *parent = nullptr,
 | 
				
			||||||
        : QObject(parent){};
 | 
					                                 const QString filePath = QString());
 | 
				
			||||||
    explicit AWAbstractFormatter(QObject *parent)
 | 
					    virtual ~AWAbstractFormatter();
 | 
				
			||||||
        : QObject(parent){};
 | 
					    virtual AWAbstractFormatter *copy(const QString _fileName) = 0;
 | 
				
			||||||
    virtual ~AWAbstractFormatter(){};
 | 
					    void copyDefaults(AWAbstractFormatter *_other) const;
 | 
				
			||||||
    virtual QString convert(const QVariant &value) const = 0;
 | 
					    virtual QString convert(const QVariant &_value) const = 0;
 | 
				
			||||||
 | 
					    QString writtableConfig() const;
 | 
				
			||||||
 | 
					    // properties
 | 
				
			||||||
 | 
					    QString comment() const;
 | 
				
			||||||
 | 
					    QString fileName() const;
 | 
				
			||||||
 | 
					    QString name() const;
 | 
				
			||||||
 | 
					    QString type() const;
 | 
				
			||||||
 | 
					    void setComment(const QString _comment = QString("empty"));
 | 
				
			||||||
 | 
					    void setName(const QString _name = QString("none"));
 | 
				
			||||||
 | 
					    void setType(const QString _type = QString("NoFormat"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public slots:
 | 
				
			||||||
 | 
					    virtual void readConfiguration();
 | 
				
			||||||
 | 
					    virtual int showConfiguration(const QVariant args = QVariant()) = 0;
 | 
				
			||||||
 | 
					    bool tryDelete() const;
 | 
				
			||||||
 | 
					    virtual void writeConfiguration() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    QString m_fileName;
 | 
				
			||||||
 | 
					    virtual void translate() = 0;
 | 
				
			||||||
 | 
					    // properties
 | 
				
			||||||
 | 
					    QString m_comment = QString("empty");
 | 
				
			||||||
 | 
					    QString m_name = QString("none");
 | 
				
			||||||
 | 
					    QString m_type = QString("NoFormat");
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -17,44 +17,69 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awdatetimeformatter.h"
 | 
					#include "awdatetimeformatter.h"
 | 
				
			||||||
 | 
					#include "ui_awdatetimeformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <KI18n/KLocalizedString>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QDateTime>
 | 
					#include <QDateTime>
 | 
				
			||||||
 | 
					#include <QDir>
 | 
				
			||||||
#include <QSettings>
 | 
					#include <QSettings>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awdebug.h"
 | 
					#include "awdebug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWDateTimeFormatter::AWDateTimeFormatter(QObject *parent,
 | 
					AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent,
 | 
				
			||||||
                                         const QString filename,
 | 
					                                         const QString filePath)
 | 
				
			||||||
                                         const QString section)
 | 
					    : AWAbstractFormatter(parent, filePath)
 | 
				
			||||||
    : AWAbstractFormatter(parent, filename, section)
 | 
					    , ui(new Ui::AWDateTimeFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    init(filename, section);
 | 
					    readConfiguration();
 | 
				
			||||||
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWDateTimeFormatter::AWDateTimeFormatter(QObject *parent, const QString format)
 | 
					AWDateTimeFormatter::AWDateTimeFormatter(const QString format, QWidget *parent)
 | 
				
			||||||
    : AWAbstractFormatter(parent)
 | 
					    : AWAbstractFormatter(parent)
 | 
				
			||||||
 | 
					    , ui(new Ui::AWDateTimeFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setFormat(format);
 | 
					    setFormat(format);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWDateTimeFormatter::~AWDateTimeFormatter()
 | 
					AWDateTimeFormatter::~AWDateTimeFormatter()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete ui;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString AWDateTimeFormatter::convert(const QVariant &value) const
 | 
					QString AWDateTimeFormatter::convert(const QVariant &_value) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Convert value" << value;
 | 
					    qCDebug(LOG_AW) << "Convert value" << _value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return value.toDateTime().toString(m_format);
 | 
					    return _value.toDateTime().toString(m_format);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_LIB) << "File" << _fileName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    AWDateTimeFormatter *item
 | 
				
			||||||
 | 
					        = new AWDateTimeFormatter(static_cast<QWidget *>(parent()), _fileName);
 | 
				
			||||||
 | 
					    copyDefaults(item);
 | 
				
			||||||
 | 
					    item->setFormat(format());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return item;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -72,13 +97,59 @@ void AWDateTimeFormatter::setFormat(const QString _format)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AWDateTimeFormatter::init(const QString filename, const QString section)
 | 
					void AWDateTimeFormatter::readConfiguration()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
 | 
					    AWAbstractFormatter::readConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QSettings settings(filename, QSettings::IniFormat);
 | 
					    QSettings settings(fileName(), QSettings::IniFormat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    settings.beginGroup(section);
 | 
					    settings.beginGroup(QString("Desktop Entry"));
 | 
				
			||||||
    setFormat(settings.value(QString("Format"), QString()).toString());
 | 
					    setFormat(settings.value(QString("Format"), m_format).toString());
 | 
				
			||||||
    settings.endGroup();
 | 
					    settings.endGroup();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int AWDateTimeFormatter::showConfiguration(const QVariant args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Q_UNUSED(args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->lineEdit_name->setText(name());
 | 
				
			||||||
 | 
					    ui->lineEdit_comment->setText(comment());
 | 
				
			||||||
 | 
					    ui->label_typeValue->setText(QString("DateTime"));
 | 
				
			||||||
 | 
					    ui->lineEdit_format->setText(m_format);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int ret = exec();
 | 
				
			||||||
 | 
					    if (ret != 1)
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    setName(ui->lineEdit_name->text());
 | 
				
			||||||
 | 
					    setComment(ui->lineEdit_comment->text());
 | 
				
			||||||
 | 
					    setType(ui->label_typeValue->text());
 | 
				
			||||||
 | 
					    setFormat(ui->lineEdit_format->text());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    writeConfiguration();
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWDateTimeFormatter::writeConfiguration() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    AWAbstractFormatter::writeConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QSettings settings(writtableConfig(), QSettings::IniFormat);
 | 
				
			||||||
 | 
					    qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.beginGroup(QString("Desktop Entry"));
 | 
				
			||||||
 | 
					    settings.setValue(QString("Format"), m_format);
 | 
				
			||||||
 | 
					    settings.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.sync();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWDateTimeFormatter::translate()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ui->label_name->setText(i18n("Name"));
 | 
				
			||||||
 | 
					    ui->label_comment->setText(i18n("Comment"));
 | 
				
			||||||
 | 
					    ui->label_type->setText(i18n("Type"));
 | 
				
			||||||
 | 
					    ui->label_format->setText(i18n("Format"));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,25 +21,36 @@
 | 
				
			|||||||
#include "awabstractformatter.h"
 | 
					#include "awabstractformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ui
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					class AWDateTimeFormatter;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AWDateTimeFormatter : public AWAbstractFormatter
 | 
					class AWDateTimeFormatter : public AWAbstractFormatter
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
    Q_PROPERTY(QString format READ format WRITE setFormat)
 | 
					    Q_PROPERTY(QString format READ format WRITE setFormat)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    explicit AWDateTimeFormatter(QObject *parent, const QString filename,
 | 
					    explicit AWDateTimeFormatter(QWidget *parent, const QString filePath);
 | 
				
			||||||
                                 const QString section);
 | 
					    explicit AWDateTimeFormatter(const QString format, QWidget *parent);
 | 
				
			||||||
    explicit AWDateTimeFormatter(QObject *parent, const QString format);
 | 
					 | 
				
			||||||
    virtual ~AWDateTimeFormatter();
 | 
					    virtual ~AWDateTimeFormatter();
 | 
				
			||||||
    QString convert(const QVariant &value) const;
 | 
					    QString convert(const QVariant &_value) const;
 | 
				
			||||||
 | 
					    AWDateTimeFormatter *copy(const QString _fileName);
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
    QString format() const;
 | 
					    QString format() const;
 | 
				
			||||||
    void setFormat(const QString _format);
 | 
					    void setFormat(const QString _format);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public slots:
 | 
				
			||||||
 | 
					    void readConfiguration();
 | 
				
			||||||
 | 
					    int showConfiguration(const QVariant args = QVariant());
 | 
				
			||||||
 | 
					    void writeConfiguration() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void init(const QString filename, const QString section);
 | 
					    Ui::AWDateTimeFormatter *ui;
 | 
				
			||||||
 | 
					    void translate();
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
    QString m_format;
 | 
					    QString m_format = QString();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										167
									
								
								sources/awesome-widget/plugin/awdatetimeformatter.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								sources/awesome-widget/plugin/awdatetimeformatter.ui
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,167 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<ui version="4.0">
 | 
				
			||||||
 | 
					 <class>AWDateTimeFormatter</class>
 | 
				
			||||||
 | 
					 <widget class="QDialog" name="AWDateTimeFormatter">
 | 
				
			||||||
 | 
					  <property name="geometry">
 | 
				
			||||||
 | 
					   <rect>
 | 
				
			||||||
 | 
					    <x>0</x>
 | 
				
			||||||
 | 
					    <y>0</y>
 | 
				
			||||||
 | 
					    <width>420</width>
 | 
				
			||||||
 | 
					    <height>157</height>
 | 
				
			||||||
 | 
					   </rect>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="windowTitle">
 | 
				
			||||||
 | 
					   <string>Configuration</string>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <layout class="QVBoxLayout" name="verticalLayout">
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_name">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_name">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Name</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_name"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_comment">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_comment">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Comment</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_comment"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_type">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_type">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Type</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_typeValue">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string/>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_format">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_format">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Format</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_format"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <spacer name="verticalSpacer">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Vertical</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="sizeHint" stdset="0">
 | 
				
			||||||
 | 
					      <size>
 | 
				
			||||||
 | 
					       <width>20</width>
 | 
				
			||||||
 | 
					       <height>40</height>
 | 
				
			||||||
 | 
					      </size>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </spacer>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="QDialogButtonBox" name="buttonBox">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="standardButtons">
 | 
				
			||||||
 | 
					      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					  </layout>
 | 
				
			||||||
 | 
					 </widget>
 | 
				
			||||||
 | 
					 <resources/>
 | 
				
			||||||
 | 
					 <connections>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>accepted()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWDateTimeFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>accept()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>248</x>
 | 
				
			||||||
 | 
					     <y>254</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>157</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>rejected()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWDateTimeFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>reject()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>316</x>
 | 
				
			||||||
 | 
					     <y>260</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>286</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					 </connections>
 | 
				
			||||||
 | 
					</ui>
 | 
				
			||||||
@ -17,51 +17,87 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awfloatformatter.h"
 | 
					#include "awfloatformatter.h"
 | 
				
			||||||
 | 
					#include "ui_awfloatformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <KI18n/KLocalizedString>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QDir>
 | 
				
			||||||
#include <QSettings>
 | 
					#include <QSettings>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awdebug.h"
 | 
					#include "awdebug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWFloatFormatter::AWFloatFormatter(QObject *parent, const QString filename,
 | 
					AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString filePath)
 | 
				
			||||||
                                   const QString section)
 | 
					    : AWAbstractFormatter(parent, filePath)
 | 
				
			||||||
    : AWAbstractFormatter(parent, filename, section)
 | 
					    , ui(new Ui::AWFloatFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    init(filename, section);
 | 
					    readConfiguration();
 | 
				
			||||||
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWFloatFormatter::AWFloatFormatter(QObject *parent, const QChar fillChar,
 | 
					AWFloatFormatter::AWFloatFormatter(const int count, const QChar fillChar,
 | 
				
			||||||
                                   const char format, const double multiplier,
 | 
					                                   const char format, const double multiplier,
 | 
				
			||||||
                                   const int precision, const double summand,
 | 
					                                   const int precision, const double summand,
 | 
				
			||||||
                                   const int width)
 | 
					                                   QWidget *parent)
 | 
				
			||||||
    : AWAbstractFormatter(parent)
 | 
					    : AWAbstractFormatter(parent)
 | 
				
			||||||
 | 
					    , ui(new Ui::AWFloatFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    setCount(count);
 | 
				
			||||||
    setFillChar(fillChar);
 | 
					    setFillChar(fillChar);
 | 
				
			||||||
    setFormat(format);
 | 
					    setFormat(format);
 | 
				
			||||||
    setMultiplier(multiplier);
 | 
					    setMultiplier(multiplier);
 | 
				
			||||||
    setPrecision(precision);
 | 
					    setPrecision(precision);
 | 
				
			||||||
    setSummand(summand);
 | 
					    setSummand(summand);
 | 
				
			||||||
    setWidth(width);
 | 
					
 | 
				
			||||||
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWFloatFormatter::~AWFloatFormatter()
 | 
					AWFloatFormatter::~AWFloatFormatter()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete ui;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString AWFloatFormatter::convert(const QVariant &value) const
 | 
					QString AWFloatFormatter::convert(const QVariant &_value) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Convert value" << value;
 | 
					    qCDebug(LOG_AW) << "Convert value" << _value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return QString("%1").arg(value.toDouble() * m_multiplier + m_summand,
 | 
					    return QString("%1").arg(_value.toDouble() * m_multiplier + m_summand,
 | 
				
			||||||
                             m_width, m_format, m_precision, m_fillChar);
 | 
					                             m_count, m_format, m_precision, m_fillChar);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_LIB) << "File" << _fileName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    AWFloatFormatter *item
 | 
				
			||||||
 | 
					        = new AWFloatFormatter(static_cast<QWidget *>(parent()), _fileName);
 | 
				
			||||||
 | 
					    copyDefaults(item);
 | 
				
			||||||
 | 
					    item->setCount(count());
 | 
				
			||||||
 | 
					    item->setFormat(format());
 | 
				
			||||||
 | 
					    item->setFillChar(fillChar());
 | 
				
			||||||
 | 
					    item->setMultiplier(multiplier());
 | 
				
			||||||
 | 
					    item->setPrecision(precision());
 | 
				
			||||||
 | 
					    item->setSummand(summand());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return item;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int AWFloatFormatter::count() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_count;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -95,9 +131,11 @@ double AWFloatFormatter::summand() const
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int AWFloatFormatter::width() const
 | 
					void AWFloatFormatter::setCount(const int _count)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return m_width;
 | 
					    qCDebug(LOG_AW) << "Set width" << _count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_count = _count;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -147,30 +185,90 @@ void AWFloatFormatter::setSummand(const double _summand)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AWFloatFormatter::setWidth(const int _width)
 | 
					void AWFloatFormatter::readConfiguration()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Set width" << _width;
 | 
					    AWAbstractFormatter::readConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_width = _width;
 | 
					    QSettings settings(fileName(), QSettings::IniFormat);
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.beginGroup(QString("Desktop Entry"));
 | 
				
			||||||
void AWFloatFormatter::init(const QString filename, const QString section)
 | 
					    setCount(settings.value(QString("Width"), m_count).toInt());
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    QSettings settings(filename, QSettings::IniFormat);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    settings.beginGroup(section);
 | 
					 | 
				
			||||||
    setFillChar(
 | 
					    setFillChar(
 | 
				
			||||||
        settings.value(QString("FillChar"), QString()).toString().at(0));
 | 
					        settings.value(QString("FillChar"), m_fillChar).toString().at(0));
 | 
				
			||||||
    setFormat(settings.value(QString("Format"), QString("f"))
 | 
					    setFormat(settings.value(QString("Format"), QString(m_format))
 | 
				
			||||||
                  .toString()
 | 
					                  .toString()
 | 
				
			||||||
                  .at(0)
 | 
					                  .at(0)
 | 
				
			||||||
                  .toLatin1());
 | 
					                  .toLatin1());
 | 
				
			||||||
    setMultiplier(settings.value(QString("Multiplier"), 1.0).toDouble());
 | 
					    setMultiplier(
 | 
				
			||||||
    setPrecision(settings.value(QString("Precision"), -1).toInt());
 | 
					        settings.value(QString("Multiplier"), m_multiplier).toDouble());
 | 
				
			||||||
    setSummand(settings.value(QString("Summand"), 0.0).toDouble());
 | 
					    setPrecision(settings.value(QString("Precision"), m_precision).toInt());
 | 
				
			||||||
    setWidth(settings.value(QString("Width"), 0).toInt());
 | 
					    setSummand(settings.value(QString("Summand"), m_summand).toDouble());
 | 
				
			||||||
    settings.endGroup();
 | 
					    settings.endGroup();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int AWFloatFormatter::showConfiguration(const QVariant args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Q_UNUSED(args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->lineEdit_name->setText(name());
 | 
				
			||||||
 | 
					    ui->lineEdit_comment->setText(comment());
 | 
				
			||||||
 | 
					    ui->label_typeValue->setText(QString("Float"));
 | 
				
			||||||
 | 
					    ui->comboBox_format->setCurrentIndex(
 | 
				
			||||||
 | 
					        ui->comboBox_format->findText(QString(m_format)));
 | 
				
			||||||
 | 
					    ui->spinBox_precision->setValue(m_precision);
 | 
				
			||||||
 | 
					    ui->spinBox_width->setValue(m_count);
 | 
				
			||||||
 | 
					    ui->lineEdit_fill->setText(QString(m_fillChar));
 | 
				
			||||||
 | 
					    ui->doubleSpinBox_multiplier->setValue(m_multiplier);
 | 
				
			||||||
 | 
					    ui->doubleSpinBox_summand->setValue(m_summand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int ret = exec();
 | 
				
			||||||
 | 
					    if (ret != 1)
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    setName(ui->lineEdit_name->text());
 | 
				
			||||||
 | 
					    setComment(ui->lineEdit_comment->text());
 | 
				
			||||||
 | 
					    setType(ui->label_typeValue->text());
 | 
				
			||||||
 | 
					    setFormat(ui->comboBox_format->currentText().at(0).toLatin1());
 | 
				
			||||||
 | 
					    setPrecision(ui->spinBox_precision->value());
 | 
				
			||||||
 | 
					    setCount(ui->spinBox_width->value());
 | 
				
			||||||
 | 
					    setFillChar(ui->lineEdit_fill->text().at(0));
 | 
				
			||||||
 | 
					    setMultiplier(ui->doubleSpinBox_multiplier->value());
 | 
				
			||||||
 | 
					    setSummand(ui->doubleSpinBox_summand->value());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    writeConfiguration();
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWFloatFormatter::writeConfiguration() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    AWAbstractFormatter::writeConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QSettings settings(writtableConfig(), QSettings::IniFormat);
 | 
				
			||||||
 | 
					    qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.beginGroup(QString("Desktop Entry"));
 | 
				
			||||||
 | 
					    settings.setValue(QString("Width"), m_count);
 | 
				
			||||||
 | 
					    settings.setValue(QString("FillChar"), m_fillChar);
 | 
				
			||||||
 | 
					    settings.setValue(QString("Format"), m_format);
 | 
				
			||||||
 | 
					    settings.setValue(QString("Multiplier"), m_multiplier);
 | 
				
			||||||
 | 
					    settings.setValue(QString("Precision"), m_precision);
 | 
				
			||||||
 | 
					    settings.setValue(QString("Summand"), m_summand);
 | 
				
			||||||
 | 
					    settings.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.sync();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWFloatFormatter::translate()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ui->label_name->setText(i18n("Name"));
 | 
				
			||||||
 | 
					    ui->label_comment->setText(i18n("Comment"));
 | 
				
			||||||
 | 
					    ui->label_type->setText(i18n("Type"));
 | 
				
			||||||
 | 
					    ui->label_format->setText(i18n("Format"));
 | 
				
			||||||
 | 
					    ui->label_precision->setText(i18n("Precision"));
 | 
				
			||||||
 | 
					    ui->label_width->setText(i18n("Width"));
 | 
				
			||||||
 | 
					    ui->label_fill->setText(i18n("Fill char"));
 | 
				
			||||||
 | 
					    ui->label_multiplier->setText(i18n("Multiplier"));
 | 
				
			||||||
 | 
					    ui->label_summand->setText(i18n("Summand"));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,48 +21,59 @@
 | 
				
			|||||||
#include "awabstractformatter.h"
 | 
					#include "awabstractformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ui
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					class AWFloatFormatter;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AWFloatFormatter : public AWAbstractFormatter
 | 
					class AWFloatFormatter : public AWAbstractFormatter
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
 | 
					    Q_PROPERTY(int count READ count WRITE setCount)
 | 
				
			||||||
    Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
 | 
					    Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
 | 
				
			||||||
    Q_PROPERTY(char format READ format WRITE setFormat)
 | 
					    Q_PROPERTY(char format READ format WRITE setFormat)
 | 
				
			||||||
    Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
 | 
					    Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
 | 
				
			||||||
    Q_PROPERTY(int precision READ precision WRITE setPrecision)
 | 
					    Q_PROPERTY(int precision READ precision WRITE setPrecision)
 | 
				
			||||||
    Q_PROPERTY(double summand READ summand WRITE setSummand)
 | 
					    Q_PROPERTY(double summand READ summand WRITE setSummand)
 | 
				
			||||||
    Q_PROPERTY(int width READ width WRITE setWidth)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    explicit AWFloatFormatter(QObject *parent, const QString filename,
 | 
					    explicit AWFloatFormatter(QWidget *parent, const QString filePath);
 | 
				
			||||||
                              const QString section);
 | 
					    explicit AWFloatFormatter(const int count, const QChar fillChar,
 | 
				
			||||||
    explicit AWFloatFormatter(QObject *parent, const QChar fillChar,
 | 
					 | 
				
			||||||
                              const char format, const double multiplier,
 | 
					                              const char format, const double multiplier,
 | 
				
			||||||
                              const int precision, const double summand,
 | 
					                              const int precision, const double summand,
 | 
				
			||||||
                              const int width);
 | 
					                              QWidget *parent);
 | 
				
			||||||
    virtual ~AWFloatFormatter();
 | 
					    virtual ~AWFloatFormatter();
 | 
				
			||||||
    QString convert(const QVariant &value) const;
 | 
					    QString convert(const QVariant &_value) const;
 | 
				
			||||||
 | 
					    AWFloatFormatter *copy(const QString _fileName);
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
 | 
					    int count() const;
 | 
				
			||||||
    QChar fillChar() const;
 | 
					    QChar fillChar() const;
 | 
				
			||||||
    char format() const;
 | 
					    char format() const;
 | 
				
			||||||
    double multiplier() const;
 | 
					    double multiplier() const;
 | 
				
			||||||
    int precision() const;
 | 
					    int precision() const;
 | 
				
			||||||
    double summand() const;
 | 
					    double summand() const;
 | 
				
			||||||
    int width() const;
 | 
					    void setCount(const int _count);
 | 
				
			||||||
    void setFillChar(const QChar _fillChar);
 | 
					    void setFillChar(const QChar _fillChar);
 | 
				
			||||||
    void setFormat(char _format);
 | 
					    void setFormat(char _format);
 | 
				
			||||||
    void setMultiplier(const double _multiplier);
 | 
					    void setMultiplier(const double _multiplier);
 | 
				
			||||||
    void setPrecision(const int _precision);
 | 
					    void setPrecision(const int _precision);
 | 
				
			||||||
    void setSummand(const double _summand);
 | 
					    void setSummand(const double _summand);
 | 
				
			||||||
    void setWidth(const int _width);
 | 
					
 | 
				
			||||||
 | 
					public slots:
 | 
				
			||||||
 | 
					    void readConfiguration();
 | 
				
			||||||
 | 
					    int showConfiguration(const QVariant args = QVariant());
 | 
				
			||||||
 | 
					    void writeConfiguration() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void init(const QString filename, const QString section);
 | 
					    Ui::AWFloatFormatter *ui;
 | 
				
			||||||
 | 
					    void translate();
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
    QChar m_fillChar;
 | 
					    int m_count = 0;
 | 
				
			||||||
    char m_format;
 | 
					    QChar m_fillChar = QChar();
 | 
				
			||||||
    double m_multiplier;
 | 
					    char m_format = 'f';
 | 
				
			||||||
    int m_precision;
 | 
					    double m_multiplier = 1.0;
 | 
				
			||||||
    double m_summand;
 | 
					    int m_precision = -1;
 | 
				
			||||||
    int m_width;
 | 
					    double m_summand = 0.0;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										317
									
								
								sources/awesome-widget/plugin/awfloatformatter.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										317
									
								
								sources/awesome-widget/plugin/awfloatformatter.ui
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,317 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<ui version="4.0">
 | 
				
			||||||
 | 
					 <class>AWFloatFormatter</class>
 | 
				
			||||||
 | 
					 <widget class="QDialog" name="AWFloatFormatter">
 | 
				
			||||||
 | 
					  <property name="geometry">
 | 
				
			||||||
 | 
					   <rect>
 | 
				
			||||||
 | 
					    <x>0</x>
 | 
				
			||||||
 | 
					    <y>0</y>
 | 
				
			||||||
 | 
					    <width>420</width>
 | 
				
			||||||
 | 
					    <height>315</height>
 | 
				
			||||||
 | 
					   </rect>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="windowTitle">
 | 
				
			||||||
 | 
					   <string>Configuration</string>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <layout class="QVBoxLayout" name="verticalLayout">
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_name">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_name">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Name</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_name"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_comment">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_comment">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Comment</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_comment"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_type">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_type">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Type</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_typeValue">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string/>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_format">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_format">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Format</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QComboBox" name="comboBox_format">
 | 
				
			||||||
 | 
					       <item>
 | 
				
			||||||
 | 
					        <property name="text">
 | 
				
			||||||
 | 
					         <string notr="true">e</string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					       </item>
 | 
				
			||||||
 | 
					       <item>
 | 
				
			||||||
 | 
					        <property name="text">
 | 
				
			||||||
 | 
					         <string notr="true">E</string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					       </item>
 | 
				
			||||||
 | 
					       <item>
 | 
				
			||||||
 | 
					        <property name="text">
 | 
				
			||||||
 | 
					         <string notr="true">f</string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					       </item>
 | 
				
			||||||
 | 
					       <item>
 | 
				
			||||||
 | 
					        <property name="text">
 | 
				
			||||||
 | 
					         <string notr="true">g</string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					       </item>
 | 
				
			||||||
 | 
					       <item>
 | 
				
			||||||
 | 
					        <property name="text">
 | 
				
			||||||
 | 
					         <string notr="true">G</string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					       </item>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_precision">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_precision">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Precision</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QSpinBox" name="spinBox_precision">
 | 
				
			||||||
 | 
					       <property name="minimum">
 | 
				
			||||||
 | 
					        <number>-1</number>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="maximum">
 | 
				
			||||||
 | 
					        <number>10000</number>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_width">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_width">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Width</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QSpinBox" name="spinBox_width">
 | 
				
			||||||
 | 
					       <property name="minimum">
 | 
				
			||||||
 | 
					        <number>-10000</number>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="maximum">
 | 
				
			||||||
 | 
					        <number>10000</number>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_fill">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_fill">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Fill char</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_fill">
 | 
				
			||||||
 | 
					       <property name="maxLength">
 | 
				
			||||||
 | 
					        <number>1</number>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="Line" name="line">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_multiplier">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_multiplier">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Multiplier</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QDoubleSpinBox" name="doubleSpinBox_multiplier">
 | 
				
			||||||
 | 
					       <property name="minimum">
 | 
				
			||||||
 | 
					        <double>-1000000000.000000000000000</double>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="maximum">
 | 
				
			||||||
 | 
					        <double>1000000000.000000000000000</double>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_summand">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_summand">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Summand</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QDoubleSpinBox" name="doubleSpinBox_summand">
 | 
				
			||||||
 | 
					       <property name="minimum">
 | 
				
			||||||
 | 
					        <double>-1000000000.000000000000000</double>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="maximum">
 | 
				
			||||||
 | 
					        <double>1000000000.000000000000000</double>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <spacer name="verticalSpacer">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Vertical</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="sizeHint" stdset="0">
 | 
				
			||||||
 | 
					      <size>
 | 
				
			||||||
 | 
					       <width>20</width>
 | 
				
			||||||
 | 
					       <height>40</height>
 | 
				
			||||||
 | 
					      </size>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </spacer>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="QDialogButtonBox" name="buttonBox">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="standardButtons">
 | 
				
			||||||
 | 
					      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					  </layout>
 | 
				
			||||||
 | 
					 </widget>
 | 
				
			||||||
 | 
					 <resources/>
 | 
				
			||||||
 | 
					 <connections>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>accepted()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWFloatFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>accept()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>248</x>
 | 
				
			||||||
 | 
					     <y>254</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>157</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>rejected()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWFloatFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>reject()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>316</x>
 | 
				
			||||||
 | 
					     <y>260</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>286</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					 </connections>
 | 
				
			||||||
 | 
					</ui>
 | 
				
			||||||
@ -17,6 +17,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "awformatterhelper.h"
 | 
					#include "awformatterhelper.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QDir>
 | 
				
			||||||
#include <QSettings>
 | 
					#include <QSettings>
 | 
				
			||||||
#include <QStandardPaths>
 | 
					#include <QStandardPaths>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -32,11 +33,10 @@ AWFormatterHelper::AWFormatterHelper(QObject *parent)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_genericConfig = QString("%1/awesomewidgets/general.ini")
 | 
					 | 
				
			||||||
                          .arg(QStandardPaths::writableLocation(
 | 
					 | 
				
			||||||
                              QStandardPaths::GenericDataLocation));
 | 
					 | 
				
			||||||
#ifdef BUILD_FUTURE
 | 
					#ifdef BUILD_FUTURE
 | 
				
			||||||
    init();
 | 
					    installDirectories();
 | 
				
			||||||
 | 
					    initFormatters();
 | 
				
			||||||
 | 
					    initKeys();
 | 
				
			||||||
#endif /* BUILD_FUTURE */
 | 
					#endif /* BUILD_FUTURE */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -46,6 +46,7 @@ AWFormatterHelper::~AWFormatterHelper()
 | 
				
			|||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_formatters.clear();
 | 
					    m_formatters.clear();
 | 
				
			||||||
 | 
					    m_formattersClasses.clear();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -65,17 +66,16 @@ QStringList AWFormatterHelper::definedFormatters() const
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWFormatterHelper::FormatterClass
 | 
					QStringList AWFormatterHelper::knownFormatters() const
 | 
				
			||||||
AWFormatterHelper::defineFormatterClass(const QString name) const
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Define formatter class for" << name;
 | 
					    return m_formattersClasses.keys();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QSettings settings(m_genericConfig, QSettings::IniFormat);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    settings.beginGroup(name);
 | 
					AWFormatterHelper::FormatterClass
 | 
				
			||||||
    QString stringType
 | 
					AWFormatterHelper::defineFormatterClass(const QString stringType) const
 | 
				
			||||||
        = settings.value(QString("Type"), QString("NoFormat")).toString();
 | 
					{
 | 
				
			||||||
    settings.endGroup();
 | 
					    qCDebug(LOG_AW) << "Define formatter class for" << stringType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FormatterClass formatter = FormatterClass::NoFormat;
 | 
					    FormatterClass formatter = FormatterClass::NoFormat;
 | 
				
			||||||
    if (stringType == QString("DateTime"))
 | 
					    if (stringType == QString("DateTime"))
 | 
				
			||||||
@ -91,35 +91,97 @@ AWFormatterHelper::defineFormatterClass(const QString name) const
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AWFormatterHelper::init()
 | 
					void AWFormatterHelper::initFormatters()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QSettings settings(m_genericConfig, QSettings::IniFormat);
 | 
					    m_formattersClasses.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i = m_directories.count() - 1; i >= 0; i--) {
 | 
				
			||||||
 | 
					        QStringList files
 | 
				
			||||||
 | 
					            = QDir(m_directories.at(i)).entryList(QDir::Files, QDir::Name);
 | 
				
			||||||
 | 
					        for (auto file : files) {
 | 
				
			||||||
 | 
					            if (!file.endsWith(QString(".desktop")))
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            qCInfo(LOG_LIB) << "Found file" << file << "in"
 | 
				
			||||||
 | 
					                            << m_directories.at(i);
 | 
				
			||||||
 | 
					            QString filePath
 | 
				
			||||||
 | 
					                = QString("%1/%2").arg(m_directories.at(i)).arg(file);
 | 
				
			||||||
 | 
					            auto metadata = readMetadata(filePath);
 | 
				
			||||||
 | 
					            QString name = metadata.first;
 | 
				
			||||||
 | 
					            if (m_formattersClasses.contains(name))
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            switch (metadata.second) {
 | 
				
			||||||
 | 
					            case FormatterClass::DateTime:
 | 
				
			||||||
 | 
					                m_formattersClasses[name]
 | 
				
			||||||
 | 
					                    = new AWDateTimeFormatter(nullptr, filePath);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case FormatterClass::Float:
 | 
				
			||||||
 | 
					                m_formattersClasses[name]
 | 
				
			||||||
 | 
					                    = new AWFloatFormatter(nullptr, filePath);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case FormatterClass::Script:
 | 
				
			||||||
 | 
					                m_formattersClasses[name]
 | 
				
			||||||
 | 
					                    = new AWScriptFormatter(nullptr, filePath);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case FormatterClass::NoFormat:
 | 
				
			||||||
 | 
					                m_formattersClasses[name]
 | 
				
			||||||
 | 
					                    = new AWNoFormatter(nullptr, filePath);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWFormatterHelper::initKeys()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    m_formatters.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QSettings settings(m_formatterConfig, QSettings::IniFormat);
 | 
				
			||||||
    settings.beginGroup(QString("Formatters"));
 | 
					    settings.beginGroup(QString("Formatters"));
 | 
				
			||||||
    QStringList keys = settings.childKeys();
 | 
					    QStringList keys = settings.childKeys();
 | 
				
			||||||
    for (auto key : keys) {
 | 
					    for (auto key : keys) {
 | 
				
			||||||
        QString name = settings.value(key).toString();
 | 
					        QString name = settings.value(key).toString();
 | 
				
			||||||
        FormatterClass formatter = defineFormatterClass(name);
 | 
					        qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key;
 | 
				
			||||||
        qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
 | 
					        m_formatters[key] = m_formattersClasses[name];
 | 
				
			||||||
                       << "defined as" << static_cast<int>(formatter);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        switch (formatter) {
 | 
					 | 
				
			||||||
        case FormatterClass::DateTime:
 | 
					 | 
				
			||||||
            m_formatters[key]
 | 
					 | 
				
			||||||
                = new AWDateTimeFormatter(this, m_genericConfig, name);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case FormatterClass::Float:
 | 
					 | 
				
			||||||
            m_formatters[key]
 | 
					 | 
				
			||||||
                = new AWFloatFormatter(this, m_genericConfig, name);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case FormatterClass::Script:
 | 
					 | 
				
			||||||
            m_formatters[key]
 | 
					 | 
				
			||||||
                = new AWScriptFormatter(this, m_genericConfig, name);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case FormatterClass::NoFormat:
 | 
					 | 
				
			||||||
            m_formatters[key] = new AWNoFormatter(this, m_genericConfig, name);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    settings.endGroup();
 | 
					    settings.endGroup();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWFormatterHelper::installDirectories()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // create directory at $HOME
 | 
				
			||||||
 | 
					    QString localDir = QString("%1/awesomewidgets/formatters")
 | 
				
			||||||
 | 
					                           .arg(QStandardPaths::writableLocation(
 | 
				
			||||||
 | 
					                               QStandardPaths::GenericDataLocation));
 | 
				
			||||||
 | 
					    QDir localDirectory;
 | 
				
			||||||
 | 
					    if (localDirectory.mkpath(localDir))
 | 
				
			||||||
 | 
					        qCInfo(LOG_LIB) << "Created directory" << localDir;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_directories = QStandardPaths::locateAll(
 | 
				
			||||||
 | 
					        QStandardPaths::GenericDataLocation,
 | 
				
			||||||
 | 
					        QString("awesomewidgets/formatters"), QStandardPaths::LocateDirectory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_formatterConfig = QString("%1/awesomewidgets/formatters/formatters.ini")
 | 
				
			||||||
 | 
					                            .arg(QStandardPaths::writableLocation(
 | 
				
			||||||
 | 
					                                QStandardPaths::GenericDataLocation));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QPair<QString, AWFormatterHelper::FormatterClass>
 | 
				
			||||||
 | 
					AWFormatterHelper::readMetadata(const QString filePath) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_AW) << "Read initial parameters from" << filePath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QSettings settings(filePath, QSettings::IniFormat);
 | 
				
			||||||
 | 
					    settings.beginGroup(QString("Desktop Entry"));
 | 
				
			||||||
 | 
					    QString name = settings.value(QString("Name"), filePath).toString();
 | 
				
			||||||
 | 
					    QString type
 | 
				
			||||||
 | 
					        = settings.value(QString("Type"), QString("NoFormat")).toString();
 | 
				
			||||||
 | 
					    FormatterClass formatter = defineFormatterClass(type);
 | 
				
			||||||
 | 
					    settings.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return QPair<QString, AWFormatterHelper::FormatterClass>(name, formatter);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -35,14 +35,21 @@ public:
 | 
				
			|||||||
    virtual ~AWFormatterHelper();
 | 
					    virtual ~AWFormatterHelper();
 | 
				
			||||||
    QString convert(const QVariant &value, const QString name) const;
 | 
					    QString convert(const QVariant &value, const QString name) const;
 | 
				
			||||||
    QStringList definedFormatters() const;
 | 
					    QStringList definedFormatters() const;
 | 
				
			||||||
 | 
					    QStringList knownFormatters() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    AWFormatterHelper::FormatterClass
 | 
					    AWFormatterHelper::FormatterClass
 | 
				
			||||||
    defineFormatterClass(const QString name) const;
 | 
					    defineFormatterClass(const QString stringType) const;
 | 
				
			||||||
    void init();
 | 
					    void initFormatters();
 | 
				
			||||||
 | 
					    void initKeys();
 | 
				
			||||||
 | 
					    void installDirectories();
 | 
				
			||||||
 | 
					    QPair<QString, AWFormatterHelper::FormatterClass>
 | 
				
			||||||
 | 
					    readMetadata(const QString filePath) const;
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
    QString m_genericConfig;
 | 
					    QStringList m_directories;
 | 
				
			||||||
 | 
					    QString m_formatterConfig;
 | 
				
			||||||
    QHash<QString, AWAbstractFormatter *> m_formatters;
 | 
					    QHash<QString, AWAbstractFormatter *> m_formatters;
 | 
				
			||||||
 | 
					    QHash<QString, AWAbstractFormatter *> m_formattersClasses;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -17,43 +17,87 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awnoformatter.h"
 | 
					#include "awnoformatter.h"
 | 
				
			||||||
 | 
					#include "ui_awnoformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <KI18n/KLocalizedString>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awdebug.h"
 | 
					#include "awdebug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWNoFormatter::AWNoFormatter(QObject *parent, const QString filename,
 | 
					AWNoFormatter::AWNoFormatter(QWidget *parent, const QString filePath)
 | 
				
			||||||
                             const QString section)
 | 
					    : AWAbstractFormatter(parent, filePath)
 | 
				
			||||||
    : AWAbstractFormatter(parent, filename, section)
 | 
					    , ui(new Ui::AWNoFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    init(filename, section);
 | 
					    readConfiguration();
 | 
				
			||||||
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWNoFormatter::AWNoFormatter(QObject *parent)
 | 
					AWNoFormatter::AWNoFormatter(QWidget *parent)
 | 
				
			||||||
    : AWAbstractFormatter(parent)
 | 
					    : AWAbstractFormatter(parent)
 | 
				
			||||||
 | 
					    , ui(new Ui::AWNoFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWNoFormatter::~AWNoFormatter()
 | 
					AWNoFormatter::~AWNoFormatter()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete ui;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString AWNoFormatter::convert(const QVariant &value) const
 | 
					QString AWNoFormatter::convert(const QVariant &_value) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Convert value" << value;
 | 
					    qCDebug(LOG_AW) << "Convert value" << _value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return value.toString();
 | 
					    return _value.toString();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AWNoFormatter::init(const QString filename, const QString section)
 | 
					AWNoFormatter *AWNoFormatter::copy(const QString _fileName)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
 | 
					    qCDebug(LOG_LIB) << "File" << _fileName;
 | 
				
			||||||
    // dummy method for future references
 | 
					
 | 
				
			||||||
 | 
					    AWNoFormatter *item
 | 
				
			||||||
 | 
					        = new AWNoFormatter(static_cast<QWidget *>(parent()), _fileName);
 | 
				
			||||||
 | 
					    copyDefaults(item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return item;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int AWNoFormatter::showConfiguration(const QVariant args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Q_UNUSED(args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->lineEdit_name->setText(name());
 | 
				
			||||||
 | 
					    ui->lineEdit_comment->setText(comment());
 | 
				
			||||||
 | 
					    ui->label_typeValue->setText(QString("NoFormat"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int ret = exec();
 | 
				
			||||||
 | 
					    if (ret != 1)
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    setName(ui->lineEdit_name->text());
 | 
				
			||||||
 | 
					    setComment(ui->lineEdit_comment->text());
 | 
				
			||||||
 | 
					    setType(ui->label_typeValue->text());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    writeConfiguration();
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWNoFormatter::translate()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ui->label_name->setText(i18n("Name"));
 | 
				
			||||||
 | 
					    ui->label_comment->setText(i18n("Comment"));
 | 
				
			||||||
 | 
					    ui->label_type->setText(i18n("Type"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,19 +21,28 @@
 | 
				
			|||||||
#include "awabstractformatter.h"
 | 
					#include "awabstractformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ui
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					class AWNoFormatter;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AWNoFormatter : public AWAbstractFormatter
 | 
					class AWNoFormatter : public AWAbstractFormatter
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    explicit AWNoFormatter(QObject *parent, const QString filename,
 | 
					    explicit AWNoFormatter(QWidget *parent, const QString filePath);
 | 
				
			||||||
                           const QString section);
 | 
					    explicit AWNoFormatter(QWidget *parent);
 | 
				
			||||||
    explicit AWNoFormatter(QObject *parent);
 | 
					 | 
				
			||||||
    virtual ~AWNoFormatter();
 | 
					    virtual ~AWNoFormatter();
 | 
				
			||||||
    QString convert(const QVariant &value) const;
 | 
					    QString convert(const QVariant &_value) const;
 | 
				
			||||||
 | 
					    AWNoFormatter *copy(const QString _fileName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public slots:
 | 
				
			||||||
 | 
					    int showConfiguration(const QVariant args = QVariant());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void init(const QString filename, const QString section);
 | 
					    Ui::AWNoFormatter *ui;
 | 
				
			||||||
 | 
					    void translate();
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										144
									
								
								sources/awesome-widget/plugin/awnoformatter.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								sources/awesome-widget/plugin/awnoformatter.ui
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,144 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<ui version="4.0">
 | 
				
			||||||
 | 
					 <class>AWNoFormatter</class>
 | 
				
			||||||
 | 
					 <widget class="QDialog" name="AWNoFormatter">
 | 
				
			||||||
 | 
					  <property name="geometry">
 | 
				
			||||||
 | 
					   <rect>
 | 
				
			||||||
 | 
					    <x>0</x>
 | 
				
			||||||
 | 
					    <y>0</y>
 | 
				
			||||||
 | 
					    <width>420</width>
 | 
				
			||||||
 | 
					    <height>128</height>
 | 
				
			||||||
 | 
					   </rect>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="windowTitle">
 | 
				
			||||||
 | 
					   <string>Configuration</string>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <layout class="QVBoxLayout" name="verticalLayout">
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_name">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_name">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Name</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_name"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_comment">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_comment">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Comment</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_comment"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_type">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_type">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Type</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_typeValue">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string/>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <spacer name="verticalSpacer">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Vertical</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="sizeHint" stdset="0">
 | 
				
			||||||
 | 
					      <size>
 | 
				
			||||||
 | 
					       <width>20</width>
 | 
				
			||||||
 | 
					       <height>40</height>
 | 
				
			||||||
 | 
					      </size>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </spacer>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="QDialogButtonBox" name="buttonBox">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="standardButtons">
 | 
				
			||||||
 | 
					      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					  </layout>
 | 
				
			||||||
 | 
					 </widget>
 | 
				
			||||||
 | 
					 <resources/>
 | 
				
			||||||
 | 
					 <connections>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>accepted()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWNoFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>accept()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>248</x>
 | 
				
			||||||
 | 
					     <y>254</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>157</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>rejected()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWNoFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>reject()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>316</x>
 | 
				
			||||||
 | 
					     <y>260</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>286</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					 </connections>
 | 
				
			||||||
 | 
					</ui>
 | 
				
			||||||
@ -17,27 +17,33 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awscriptformatter.h"
 | 
					#include "awscriptformatter.h"
 | 
				
			||||||
 | 
					#include "ui_awscriptformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <KI18n/KLocalizedString>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QDir>
 | 
				
			||||||
#include <QJSEngine>
 | 
					#include <QJSEngine>
 | 
				
			||||||
#include <QSettings>
 | 
					#include <QSettings>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "awdebug.h"
 | 
					#include "awdebug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWScriptFormatter::AWScriptFormatter(QObject *parent, const QString filename,
 | 
					AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString filePath)
 | 
				
			||||||
                                     const QString section)
 | 
					    : AWAbstractFormatter(parent, filePath)
 | 
				
			||||||
    : AWAbstractFormatter(parent, filename, section)
 | 
					    , ui(new Ui::AWScriptFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    init(filename, section);
 | 
					    readConfiguration();
 | 
				
			||||||
    initProgram();
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWScriptFormatter::AWScriptFormatter(QObject *parent, const bool appendCode,
 | 
					AWScriptFormatter::AWScriptFormatter(const bool appendCode, const QString code,
 | 
				
			||||||
                                     const QString code, const bool hasReturn)
 | 
					                                     const bool hasReturn, QWidget *parent)
 | 
				
			||||||
    : AWAbstractFormatter(parent)
 | 
					    : AWAbstractFormatter(parent)
 | 
				
			||||||
 | 
					    , ui(new Ui::AWScriptFormatter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -45,23 +51,28 @@ AWScriptFormatter::AWScriptFormatter(QObject *parent, const bool appendCode,
 | 
				
			|||||||
    setCode(code);
 | 
					    setCode(code);
 | 
				
			||||||
    setHasReturn(hasReturn);
 | 
					    setHasReturn(hasReturn);
 | 
				
			||||||
    initProgram();
 | 
					    initProgram();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->setupUi(this);
 | 
				
			||||||
 | 
					    translate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AWScriptFormatter::~AWScriptFormatter()
 | 
					AWScriptFormatter::~AWScriptFormatter()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
					    qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete ui;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString AWScriptFormatter::convert(const QVariant &value) const
 | 
					QString AWScriptFormatter::convert(const QVariant &_value) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Convert value" << value;
 | 
					    qCDebug(LOG_AW) << "Convert value" << _value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // init engine
 | 
					    // init engine
 | 
				
			||||||
    QJSEngine engine;
 | 
					    QJSEngine engine;
 | 
				
			||||||
    QJSValue fn = engine.evaluate(m_program);
 | 
					    QJSValue fn = engine.evaluate(m_program);
 | 
				
			||||||
    QJSValueList args = QJSValueList() << value.toString();
 | 
					    QJSValueList args = QJSValueList() << _value.toString();
 | 
				
			||||||
    QJSValue result = fn.call(args);
 | 
					    QJSValue result = fn.call(args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (result.isError()) {
 | 
					    if (result.isError()) {
 | 
				
			||||||
@ -75,6 +86,21 @@ QString AWScriptFormatter::convert(const QVariant &value) const
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    qCDebug(LOG_LIB) << "File" << _fileName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    AWScriptFormatter *item
 | 
				
			||||||
 | 
					        = new AWScriptFormatter(static_cast<QWidget *>(parent()), _fileName);
 | 
				
			||||||
 | 
					    copyDefaults(item);
 | 
				
			||||||
 | 
					    item->setAppendCode(appendCode());
 | 
				
			||||||
 | 
					    item->setCode(code());
 | 
				
			||||||
 | 
					    item->setHasReturn(hasReturn());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return item;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool AWScriptFormatter::appendCode() const
 | 
					bool AWScriptFormatter::appendCode() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return m_appendCode;
 | 
					    return m_appendCode;
 | 
				
			||||||
@ -123,17 +149,65 @@ void AWScriptFormatter::setHasReturn(const bool _hasReturn)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AWScriptFormatter::init(const QString filename, const QString section)
 | 
					void AWScriptFormatter::readConfiguration()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
 | 
					    AWAbstractFormatter::readConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QSettings settings(filename, QSettings::IniFormat);
 | 
					    QSettings settings(fileName(), QSettings::IniFormat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    settings.beginGroup(section);
 | 
					    settings.beginGroup(QString("Desktop Entry"));
 | 
				
			||||||
    setAppendCode(settings.value(QString("AppendCode"), true).toBool());
 | 
					    setAppendCode(settings.value(QString("AppendCode"), m_appendCode).toBool());
 | 
				
			||||||
    setCode(settings.value(QString("Code"), QString()).toString());
 | 
					    setCode(settings.value(QString("Code"), m_code).toString());
 | 
				
			||||||
    setHasReturn(settings.value(QString("HasReturn"), false).toBool());
 | 
					    setHasReturn(settings.value(QString("HasReturn"), m_hasReturn).toBool());
 | 
				
			||||||
    settings.endGroup();
 | 
					    settings.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    initProgram();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int AWScriptFormatter::showConfiguration(const QVariant args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Q_UNUSED(args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->lineEdit_name->setText(name());
 | 
				
			||||||
 | 
					    ui->lineEdit_comment->setText(comment());
 | 
				
			||||||
 | 
					    ui->label_typeValue->setText(QString("Script"));
 | 
				
			||||||
 | 
					    ui->checkBox_appendCode->setCheckState(m_appendCode ? Qt::Checked
 | 
				
			||||||
 | 
					                                                        : Qt::Unchecked);
 | 
				
			||||||
 | 
					    ui->checkBox_hasReturn->setCheckState(m_hasReturn ? Qt::Checked
 | 
				
			||||||
 | 
					                                                      : Qt::Unchecked);
 | 
				
			||||||
 | 
					    ui->textEdit_code->setPlainText(m_code);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int ret = exec();
 | 
				
			||||||
 | 
					    if (ret != 1)
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    setName(ui->lineEdit_name->text());
 | 
				
			||||||
 | 
					    setComment(ui->lineEdit_comment->text());
 | 
				
			||||||
 | 
					    setType(ui->label_typeValue->text());
 | 
				
			||||||
 | 
					    setAppendCode(ui->checkBox_appendCode->checkState() == Qt::Checked);
 | 
				
			||||||
 | 
					    setHasReturn(ui->checkBox_hasReturn->checkState() == Qt::Checked);
 | 
				
			||||||
 | 
					    setCode(ui->textEdit_code->toPlainText());
 | 
				
			||||||
 | 
					    initProgram();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    writeConfiguration();
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWScriptFormatter::writeConfiguration() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    AWAbstractFormatter::writeConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QSettings settings(writtableConfig(), QSettings::IniFormat);
 | 
				
			||||||
 | 
					    qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.beginGroup(QString("Desktop Entry"));
 | 
				
			||||||
 | 
					    settings.setValue(QString("AppendCode"), m_appendCode);
 | 
				
			||||||
 | 
					    settings.setValue(QString("Code"), m_code);
 | 
				
			||||||
 | 
					    settings.setValue(QString("HasReturn"), m_hasReturn);
 | 
				
			||||||
 | 
					    settings.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    settings.sync();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -149,3 +223,14 @@ void AWScriptFormatter::initProgram()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    qCInfo(LOG_AW) << "Create JS engine with code" << m_program;
 | 
					    qCInfo(LOG_AW) << "Create JS engine with code" << m_program;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AWScriptFormatter::translate()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ui->label_name->setText(i18n("Name"));
 | 
				
			||||||
 | 
					    ui->label_comment->setText(i18n("Comment"));
 | 
				
			||||||
 | 
					    ui->label_type->setText(i18n("Type"));
 | 
				
			||||||
 | 
					    ui->checkBox_appendCode->setText(i18n("Append code"));
 | 
				
			||||||
 | 
					    ui->checkBox_hasReturn->setText(i18n("Has return"));
 | 
				
			||||||
 | 
					    ui->label_code->setText(i18n("Code"));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,6 +21,11 @@
 | 
				
			|||||||
#include "awabstractformatter.h"
 | 
					#include "awabstractformatter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ui
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					class AWScriptFormatter;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AWScriptFormatter : public AWAbstractFormatter
 | 
					class AWScriptFormatter : public AWAbstractFormatter
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
@ -30,12 +35,12 @@ class AWScriptFormatter : public AWAbstractFormatter
 | 
				
			|||||||
    Q_PROPERTY(QString program READ program)
 | 
					    Q_PROPERTY(QString program READ program)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    explicit AWScriptFormatter(QObject *parent, const QString filename,
 | 
					    explicit AWScriptFormatter(QWidget *parent, const QString filePath);
 | 
				
			||||||
                               const QString section);
 | 
					    explicit AWScriptFormatter(const bool appendCode, const QString code,
 | 
				
			||||||
    explicit AWScriptFormatter(QObject *parent, const bool appendCode,
 | 
					                               const bool hasReturn, QWidget *parent);
 | 
				
			||||||
                               const QString code, const bool hasReturn);
 | 
					 | 
				
			||||||
    virtual ~AWScriptFormatter();
 | 
					    virtual ~AWScriptFormatter();
 | 
				
			||||||
    QString convert(const QVariant &value) const;
 | 
					    QString convert(const QVariant &_value) const;
 | 
				
			||||||
 | 
					    AWScriptFormatter *copy(const QString _fileName);
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
    bool appendCode() const;
 | 
					    bool appendCode() const;
 | 
				
			||||||
    QString code() const;
 | 
					    QString code() const;
 | 
				
			||||||
@ -45,13 +50,19 @@ public:
 | 
				
			|||||||
    void setCode(const QString _code);
 | 
					    void setCode(const QString _code);
 | 
				
			||||||
    void setHasReturn(const bool _hasReturn);
 | 
					    void setHasReturn(const bool _hasReturn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public slots:
 | 
				
			||||||
 | 
					    void readConfiguration();
 | 
				
			||||||
 | 
					    int showConfiguration(const QVariant args = QVariant());
 | 
				
			||||||
 | 
					    void writeConfiguration() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void init(const QString filename, const QString section);
 | 
					    Ui::AWScriptFormatter *ui;
 | 
				
			||||||
    void initProgram();
 | 
					    void initProgram();
 | 
				
			||||||
 | 
					    void translate();
 | 
				
			||||||
    // properties
 | 
					    // properties
 | 
				
			||||||
    bool m_appendCode;
 | 
					    bool m_appendCode = true;
 | 
				
			||||||
    QString m_code;
 | 
					    QString m_code = QString();
 | 
				
			||||||
    bool m_hasReturn;
 | 
					    bool m_hasReturn = false;
 | 
				
			||||||
    QString m_program;
 | 
					    QString m_program;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										212
									
								
								sources/awesome-widget/plugin/awscriptformatter.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										212
									
								
								sources/awesome-widget/plugin/awscriptformatter.ui
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,212 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<ui version="4.0">
 | 
				
			||||||
 | 
					 <class>AWScriptFormatter</class>
 | 
				
			||||||
 | 
					 <widget class="QDialog" name="AWScriptFormatter">
 | 
				
			||||||
 | 
					  <property name="geometry">
 | 
				
			||||||
 | 
					   <rect>
 | 
				
			||||||
 | 
					    <x>0</x>
 | 
				
			||||||
 | 
					    <y>0</y>
 | 
				
			||||||
 | 
					    <width>420</width>
 | 
				
			||||||
 | 
					    <height>315</height>
 | 
				
			||||||
 | 
					   </rect>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="windowTitle">
 | 
				
			||||||
 | 
					   <string>Configuration</string>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <layout class="QVBoxLayout" name="verticalLayout">
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_name">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_name">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Name</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_name"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_comment">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_comment">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Comment</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLineEdit" name="lineEdit_comment"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_type">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_type">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Type</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="alignment">
 | 
				
			||||||
 | 
					        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_typeValue">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string/>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_appendCode">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <spacer name="spacer_appendCode">
 | 
				
			||||||
 | 
					       <property name="orientation">
 | 
				
			||||||
 | 
					        <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="sizeHint" stdset="0">
 | 
				
			||||||
 | 
					        <size>
 | 
				
			||||||
 | 
					         <width>40</width>
 | 
				
			||||||
 | 
					         <height>20</height>
 | 
				
			||||||
 | 
					        </size>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </spacer>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QCheckBox" name="checkBox_appendCode">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Append code</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QHBoxLayout" name="layout_hasReturn">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <spacer name="spacer_hasReturn">
 | 
				
			||||||
 | 
					       <property name="orientation">
 | 
				
			||||||
 | 
					        <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="sizeHint" stdset="0">
 | 
				
			||||||
 | 
					        <size>
 | 
				
			||||||
 | 
					         <width>40</width>
 | 
				
			||||||
 | 
					         <height>20</height>
 | 
				
			||||||
 | 
					        </size>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </spacer>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QCheckBox" name="checkBox_hasReturn">
 | 
				
			||||||
 | 
					       <property name="sizePolicy">
 | 
				
			||||||
 | 
					        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
 | 
				
			||||||
 | 
					         <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					         <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					        </sizepolicy>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Has return</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="Line" name="line">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <layout class="QVBoxLayout" name="layout_code">
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QLabel" name="label_code">
 | 
				
			||||||
 | 
					       <property name="text">
 | 
				
			||||||
 | 
					        <string>Code</string>
 | 
				
			||||||
 | 
					       </property>
 | 
				
			||||||
 | 
					      </widget>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					     <item>
 | 
				
			||||||
 | 
					      <widget class="QTextEdit" name="textEdit_code"/>
 | 
				
			||||||
 | 
					     </item>
 | 
				
			||||||
 | 
					    </layout>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="QDialogButtonBox" name="buttonBox">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="standardButtons">
 | 
				
			||||||
 | 
					      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					  </layout>
 | 
				
			||||||
 | 
					 </widget>
 | 
				
			||||||
 | 
					 <resources/>
 | 
				
			||||||
 | 
					 <connections>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>accepted()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWScriptFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>accept()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>248</x>
 | 
				
			||||||
 | 
					     <y>254</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>157</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>rejected()</signal>
 | 
				
			||||||
 | 
					   <receiver>AWScriptFormatter</receiver>
 | 
				
			||||||
 | 
					   <slot>reject()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>316</x>
 | 
				
			||||||
 | 
					     <y>260</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>286</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					 </connections>
 | 
				
			||||||
 | 
					</ui>
 | 
				
			||||||
		Reference in New Issue
	
	Block a user