first class into plasma from kicker: applet info. includes unit testing.
may not currently even build, however, as my kdelibs is currently messed up and svn is not cooperating. and by "may not" i mean "probably won't" but i don't want to lose this work. svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=457909
This commit is contained in:
commit
7b202ba764
204
appletinfo.cpp
Normal file
204
appletinfo.cpp
Normal file
@ -0,0 +1,204 @@
|
||||
/*****************************************************************
|
||||
Copyright (c) 2000-2001 Matthias Elter <elter@kde.org>
|
||||
Copyright (c) 2001 John Firebaugh <jfirebaugh@kde.org>
|
||||
Copyright (c) 2001-2005 Aaron Seigo <aseigo@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
******************************************************************/
|
||||
|
||||
#include <qfileinfo.h>
|
||||
#include <kdesktopfile.h>
|
||||
#include <kapplication.h>
|
||||
|
||||
#include "appletinfo.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AppletInfo::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
unique(false),
|
||||
hidden(false)
|
||||
{}
|
||||
|
||||
QString name;
|
||||
QString comment;
|
||||
QString icon;
|
||||
QString lib;
|
||||
QString languageBindings;
|
||||
QString desktopFile;
|
||||
QString desktopFilePath;
|
||||
bool unique;
|
||||
bool hidden;
|
||||
};
|
||||
|
||||
AppletInfo::AppletInfo(const QString& deskFile)
|
||||
{
|
||||
d = new Private;
|
||||
QFileInfo fi(deskFile);
|
||||
d->desktopFilePath = fi.absFilePath();
|
||||
d->desktopFile = fi.fileName();
|
||||
|
||||
KDesktopFile df(deskFile);
|
||||
|
||||
// set the appletssimple attributes
|
||||
setName(df.readName());
|
||||
setComment(df.readComment());
|
||||
setIcon(df.readIcon());
|
||||
|
||||
// library
|
||||
setLibrary(df.readEntry("X-KDE-Library"));
|
||||
|
||||
// language the applet is written in
|
||||
setLanguage(df.readEntry("X-KDE-LanguageBindings", "native").toLower());
|
||||
|
||||
// is it a unique applet?
|
||||
setUnique(df.readBoolEntry("X-KDE-UniqueApplet", false));
|
||||
|
||||
// should it be shown in the gui?
|
||||
d->hidden = df.readBoolEntry("Hidden", false);
|
||||
}
|
||||
|
||||
AppletInfo::AppletInfo(const AppletInfo ©)
|
||||
{
|
||||
d = new Private;
|
||||
*d = *copy.d;
|
||||
}
|
||||
|
||||
AppletInfo::~AppletInfo()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
AppletInfo& AppletInfo::operator=(const AppletInfo &rhs)
|
||||
{
|
||||
*d = *rhs.d;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
QString AppletInfo::name() const
|
||||
{
|
||||
return d->name;
|
||||
}
|
||||
|
||||
QString AppletInfo::comment() const
|
||||
{
|
||||
return d->comment;
|
||||
}
|
||||
|
||||
QString AppletInfo::icon() const
|
||||
{
|
||||
return d->icon;
|
||||
}
|
||||
|
||||
QString AppletInfo::library() const
|
||||
{
|
||||
return d->lib;
|
||||
}
|
||||
|
||||
QString AppletInfo::desktopFilePath() const
|
||||
{
|
||||
return d->desktopFilePath;
|
||||
}
|
||||
|
||||
QString AppletInfo::desktopFile() const
|
||||
{
|
||||
return d->desktopFile;
|
||||
}
|
||||
|
||||
QString AppletInfo::generateConfigFileName() const
|
||||
{
|
||||
// generate a config file base name from the library name
|
||||
QString configFile = "plasmaApplet_" + d->lib.lower();
|
||||
|
||||
if (d->unique)
|
||||
{
|
||||
d->configFile.append("rc");
|
||||
}
|
||||
else
|
||||
{
|
||||
d->configFile.append("_")
|
||||
.append(kapp->randomString(20).lower())
|
||||
.append("_rc");
|
||||
}
|
||||
|
||||
return configFile;
|
||||
}
|
||||
|
||||
bool AppletInfo::unique() const
|
||||
{
|
||||
return d->unique;
|
||||
}
|
||||
|
||||
bool AppletInfo::hidden() const
|
||||
{
|
||||
return d->hidden;
|
||||
}
|
||||
|
||||
void AppletInfo::setName(const QString &name)
|
||||
{
|
||||
d->name = name;
|
||||
}
|
||||
|
||||
void AppletInfo::setComment(const QString &comment)
|
||||
{
|
||||
d->comment = comment;
|
||||
}
|
||||
|
||||
void AppletInfo::setIcon(const QString &icon)
|
||||
{
|
||||
d->icon = icon;
|
||||
}
|
||||
|
||||
void AppletInfo::setLibrary(const QString &lib)
|
||||
{
|
||||
d->lib = lib;
|
||||
}
|
||||
|
||||
void AppletInfo::setUnique(bool u)
|
||||
{
|
||||
d->unique = u;
|
||||
}
|
||||
|
||||
bool AppletInfo::operator!=(const AppletInfo& rhs) const
|
||||
{
|
||||
return configFile() != rhs.configFile();
|
||||
}
|
||||
|
||||
bool AppletInfo::operator==(const AppletInfo& rhs) const
|
||||
{
|
||||
return configFile() == rhs.configFile();
|
||||
}
|
||||
|
||||
bool AppletInfo::operator<(const AppletInfo& rhs) const
|
||||
{
|
||||
return name().lower() < rhs.name().lower();
|
||||
}
|
||||
|
||||
bool AppletInfo::operator>(const AppletInfo& rhs) const
|
||||
{
|
||||
return name().lower() > rhs.name().lower();
|
||||
}
|
||||
|
||||
bool AppletInfo::operator<=(const AppletInfo& rhs) const
|
||||
{
|
||||
return name().lower() <= rhs.name().lower();
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
161
appletinfo.h
Normal file
161
appletinfo.h
Normal file
@ -0,0 +1,161 @@
|
||||
/*****************************************************************
|
||||
Copyright (c) 2000-2001 Matthias Elter <elter@kde.org>
|
||||
Copyright (c) 2001 John Firebaugh <jfirebaugh@kde.org>
|
||||
Copyright (c) 2001-2005 Aaron Seigo <aseigo@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
******************************************************************/
|
||||
|
||||
#ifndef appletinfo_h_
|
||||
#define appletinfo_h_
|
||||
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
|
||||
#include <kdemacros.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class KDE_EXPORT AppletInfo
|
||||
{
|
||||
public:
|
||||
typedef QList<AppletInfo> List;
|
||||
typedef QMap<QObject*, AppletInfo*> Dict;
|
||||
|
||||
/**
|
||||
* AppletInfo constructor
|
||||
* Each AppletInfo describes a specific applet
|
||||
* @arg desktopFile the name of the desktop file describing this applet
|
||||
*/
|
||||
AppletInfo(const QString& desktopFile = QString::null);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~AppletInfo();
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
AppletInfo(const AppletInfo& copy);
|
||||
|
||||
/**
|
||||
* Returns the name of the applet, suitable for use in user interfaces.
|
||||
*/
|
||||
QString name() const;
|
||||
|
||||
/**
|
||||
* Returns a descriptive comment for the applet, suitable for use in
|
||||
* user interfaces.
|
||||
*/
|
||||
QString comment() const;
|
||||
|
||||
/**
|
||||
* Returns the type of the applet, allowing one to distinguish between
|
||||
* applets, buttons
|
||||
*/
|
||||
QString icon() const;
|
||||
|
||||
/**
|
||||
* Returns the name of the library containing the applet
|
||||
*/
|
||||
QString library() const;
|
||||
|
||||
/**
|
||||
* Returns the language this applet is written in. "native" means it is
|
||||
* a compiled plugin that can be loaded via dlopen. anything else is
|
||||
* taken to be the name of the language (and therefore the bindings)
|
||||
* required for this applet, e.g. "javascript"
|
||||
*/
|
||||
QString languageBindings() const;
|
||||
|
||||
/**
|
||||
* Returns the full path to the desktop file being used for this applet
|
||||
*/
|
||||
QString desktopFilePath() const;
|
||||
|
||||
/**
|
||||
* Returns the name of the desktop file that describes this applet
|
||||
*/
|
||||
QString desktopFile() const;
|
||||
|
||||
/**
|
||||
* Returns a configuration file name that can be used for an instance
|
||||
* of this applet. If it is a unique applet, this will return the same
|
||||
* name each time, otherwise each time this is called the name may be
|
||||
* different.
|
||||
*/
|
||||
QString generateConfigFileName() const;
|
||||
|
||||
/**
|
||||
* Some applets only allow for one instance of the applet to be
|
||||
* instantiated at a time. This method returns true if this is the case
|
||||
* for this applet.
|
||||
*/
|
||||
bool unique() const;
|
||||
|
||||
/**
|
||||
* Not all applets are meant to be visible to the user, though they may
|
||||
* be available for use by the application internally. This method
|
||||
* returns true if this is the case for this applet.
|
||||
*/
|
||||
bool hidden() const;
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*/
|
||||
AppletInfo &operator=(const AppletInfo& rhs);
|
||||
|
||||
/**
|
||||
* Less than operator, for sorting by name in lists
|
||||
*/
|
||||
bool operator<(const AppletInfo& rhs) const;
|
||||
|
||||
/**
|
||||
* Greater than operator, for sorting by name in lists
|
||||
*/
|
||||
bool operator>(const AppletInfo& rhs) const;
|
||||
|
||||
/**
|
||||
* Less than or equals to operator, for sorting by name in lists
|
||||
*/
|
||||
bool operator<=(const AppletInfo& rhs) const;
|
||||
|
||||
/**
|
||||
* Inequality operator, for sorting by name in lists
|
||||
*/
|
||||
bool operator!=(const AppletInfo& rhs) const;
|
||||
|
||||
/**
|
||||
* Less than operator, for sorting by name in lists
|
||||
*/
|
||||
bool operator==(const AppletInfo& rhs) const;
|
||||
|
||||
private:
|
||||
void setName(const QString &name);
|
||||
void setComment(const QString &comment);
|
||||
void setIcon(const QString &icon);
|
||||
void setLibrary(const QString &lib);
|
||||
void setUnique(bool u);
|
||||
|
||||
class Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif
|
9
tests/nativeApplet.desktop
Normal file
9
tests/nativeApplet.desktop
Normal file
@ -0,0 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Type=Plugin
|
||||
Encoding=UTF-8
|
||||
Name=Non-Unique Native Applet
|
||||
Comment=A natively compiled applet
|
||||
Icon=native
|
||||
|
||||
X-KDE-Library=plasma_applet_native
|
||||
X-KDE-UniqueApplet=false
|
208
tests/testAppletInfo.cpp
Normal file
208
tests/testAppletInfo.cpp
Normal file
@ -0,0 +1,208 @@
|
||||
/*
|
||||
Unit tests for Plasma::AppletInfo
|
||||
|
||||
Copyright (C) 2005 Aaron Seigo <aseigo@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as published by
|
||||
the Free Software Foundation.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include "testAppletInfo.h"
|
||||
#include "appletInfo.h"
|
||||
|
||||
TestAppletInfo::TestAppletInfo(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
QString pwd = QDir::currentPath();
|
||||
notUniqueNative = new Plasma::AppletInfo(pwd + "/nativeApplet.desktop");
|
||||
uniqueJavascript = new Plasma::AppletInfo(pwd + "/uniqueJavaScriptApplet.desktop");
|
||||
}
|
||||
|
||||
void TestAppletInfo::name_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.name()
|
||||
<< "Non-Unique Native Applet";
|
||||
*t.newData("Unique Javascript Applet") << t.name()
|
||||
<< "Unique Javascript Applet";
|
||||
}
|
||||
|
||||
void TestAppletInfo::name()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::comment_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.comment()
|
||||
<< "A natively compiled applet";
|
||||
*t.newData("Unique Javascript Applet") << t.comment()
|
||||
<< "An applet written in JavaScript";
|
||||
}
|
||||
|
||||
void TestAppletInfo::comment()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::icon_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.icon()
|
||||
<< "native";
|
||||
*t.newData("Unique Javascript Applet") << t.icon()
|
||||
<< "javascript";
|
||||
}
|
||||
|
||||
void TestAppletInfo::icon()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::library_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.library()
|
||||
<< "plasma_applet_native";
|
||||
*t.newData("Unique Javascript Applet") << t.library()
|
||||
<< "plasma_applet_javascript";
|
||||
}
|
||||
|
||||
void TestAppletInfo::library()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::languageBindings_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.languageBindings()
|
||||
<< "native";
|
||||
*t.newData("Unique Javascript Applet") << t.languageBindings()
|
||||
<< "javascript";
|
||||
}
|
||||
|
||||
void TestAppletInfo::languageBindings()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::desktopFilePath_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
QString pwd = QDir::currentPath();
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.desktopFilePath()
|
||||
<< pwd + "/nativeApplet.desktop";
|
||||
*t.newData("Unique Javascript Applet") << t.desktopFilePath()
|
||||
<< pwd + "/uniqueJavaScriptApplet.desktop";
|
||||
}
|
||||
|
||||
void TestAppletInfo::desktopFilePath()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::desktopFile_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.desktopFile()
|
||||
<< "nativeApplet.desktop";
|
||||
*t.newData("Unique Javascript Applet") << t.desktopFile()
|
||||
<< "uniqueJavaScriptApplet.desktop";
|
||||
}
|
||||
|
||||
void TestAppletInfo::desktopFile()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::desktopFile_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.unique()
|
||||
<< "nativeApplet.desktop";
|
||||
*t.newData("Unique Javascript Applet") << t.unique()
|
||||
<< "uniqueJavaScriptApplet.desktop";
|
||||
}
|
||||
|
||||
void TestAppletInfo::unique()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
void TestAppletInfo::hidden_data(QtTestTable &t)
|
||||
{
|
||||
t.defineElement("QString", "expected");
|
||||
t.defineElement("QString", "actual");
|
||||
|
||||
*t.newData("Non-Unique Native Applet") << t.unique()
|
||||
<< "nativeApplet.desktop";
|
||||
*t.newData("Unique Javascript Applet") << t.unique()
|
||||
<< "uniqueJavaScriptApplet.desktop";
|
||||
}
|
||||
|
||||
void TestAppletInfo::hidden()
|
||||
{
|
||||
FETCH(QString, expected);
|
||||
FETCH(QString, actual);
|
||||
|
||||
COMPARE(expected, actual);
|
||||
}
|
||||
|
||||
QTTEST_MAIN(TestQString)
|
||||
#include "testAppletInfo.moc"
|
54
tests/testAppletInfo.h
Normal file
54
tests/testAppletInfo.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Unit tests for Plasma::AppletInfo
|
||||
|
||||
Copyright (C) 2005 Aaron Seigo <aseigo@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as published by
|
||||
the Free Software Foundation.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
class Plasma::AppletInfo;
|
||||
|
||||
class TestAppletInfo: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TestAppletInfo(QObject* parent = 0);
|
||||
|
||||
private slots:
|
||||
void name_data(QTestTable& t);
|
||||
void name();
|
||||
void comment_data(QTestTable& t);
|
||||
void comment();
|
||||
void icon_data(QTestTable& t);
|
||||
void icon();
|
||||
void library_data(QTestTable& t);
|
||||
void library();
|
||||
void languageBindings_data(QTestTable& t);
|
||||
void languageBindings();
|
||||
void desktopFilePath_data(QTestTable& t);
|
||||
void desktopFilePath();
|
||||
void desktopFile_data(QTestTable& t);
|
||||
void desktopFile();
|
||||
void unique_data(QTestTable& t);
|
||||
void unique();
|
||||
void hidden_data(QTestTable& t);
|
||||
void hidden();
|
||||
|
||||
private:
|
||||
Plasma::AppletInfo* notUniqueNative;
|
||||
Plasma::AppletInfo* uniqueJavascript;
|
||||
};
|
10
tests/uniqueJavaScriptApplet.desktop
Normal file
10
tests/uniqueJavaScriptApplet.desktop
Normal file
@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Type=Plugin
|
||||
Encoding=UTF-8
|
||||
Name=Unique Javascript Applet
|
||||
Comment=An applet written in JavaScript
|
||||
Icon=javascript
|
||||
|
||||
X-KDE-Library=plasma_applet_javascript
|
||||
X-KDE-LanguageBindings=JavaScript
|
||||
X-KDE-UniqueApplet=true
|
Loading…
Reference in New Issue
Block a user