Am 15. Januar 2009 17:39 schrieb Aaron J. Seigo <[email protected]>:
> On Thursday 15 January 2009, Philipp Klaffert wrote:
> > thanks for your reply and for the link. For fixing the krazy2 issues
> > correctly I changed QString to QLatin1String. I understand your point of
> > view with "readability" but I won't decide which way is better. I think
> the
> > explicit conversion of these Strings makes the understanding of the code
> > not so much harder...
>
> what jumps out at me is that we have duplications of strings. not fun. if
> the
> string is changed in one place, it ends up needing to be changed
> everywhere.
> oh nos!
>
> so ... my suggestion is this:
>
> create as set of static const QString's in the TwitterEngine class and
> initialize them to the values... e.g.:
>
> const QString TwitterEngine::profilePrefix("Profile:");
>
> then the calls become:
>
> name.startsWith(profilePrefix);
>
> no more duplicated strings and no more crazy issues. huzzah!
>
> thanks for working on these, btw =)
>
> --
> Aaron J. Seigo
> humru othro a kohnu se
> GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA EE75 D6B7 2EB1 A7F1 DB43
>
> KDE core developer sponsored by Qt Software
>
>
> _______________________________________________
> Plasma-devel mailing list
> [email protected]
> https://mail.kde.org/mailman/listinfo/plasma-devel
>
>
Thanks for your advice. After reading your mail I asked myself why I got
that idea not in first place :)
I've now swapped all the Strings with constants and so, just 3 objects an no
more krazy complaining for at least these issues.
Regards
Philipp Klaffert
Index: dataengines/twitter/timelinesource.cpp
===================================================================
--- dataengines/twitter/timelinesource.cpp (Revision 911365)
+++ dataengines/twitter/timelinesource.cpp (Arbeitskopie)
@@ -76,7 +76,7 @@
m_job(0)
{
//who should be something like u...@http://twitter.com, if there isn't any @, http://twitter.com will be the default
- QStringList account = who.split("@");
+ QStringList account = who.split('@');
if (account.count() == 2){
m_serviceBaseUrl = KUrl(account.at(1));
}else{
Index: dataengines/twitter/twitterengine.cpp
===================================================================
--- dataengines/twitter/twitterengine.cpp (Revision 911365)
+++ dataengines/twitter/twitterengine.cpp (Arbeitskopie)
@@ -30,11 +30,14 @@
#include <KDebug>
#include <KUrl>
#include <ksocketfactory.h>
-#include <KUrl>
#include "timelinesource.h"
#include "imagesource.h"
+const QString TwitterEngine::timelinePrefix("Timeline:");
+const QString TwitterEngine::timelineWithFriendsPrefix("TimelineWithFriends:");
+const QString TwitterEngine::profilePrefix("Profile:");
+
TwitterEngine::TwitterEngine(QObject* parent, const QVariantList& args)
: Plasma::DataEngine(parent, args)
{
@@ -54,7 +57,7 @@
return true;
}
- if (!name.startsWith("Timeline:") && !name.startsWith("TimelineWithFriends:") && !name.startsWith("Profile:")) {
+ if (!name.startsWith(timelinePrefix) && !name.startsWith(timelineWithFriendsPrefix) && !name.startsWith(profilePrefix)) {
return false;
}
@@ -83,22 +86,22 @@
{
//kDebug() << name;
//right now it only makes sense to do an update on timelines
- if (!name.startsWith("Timeline:") && !name.startsWith("TimelineWithFriends:") && !name.startsWith("Profile:")) {
+ if (!name.startsWith(timelinePrefix) && !name.startsWith(timelineWithFriendsPrefix) && !name.startsWith(profilePrefix)) {
return false;
}
TimelineSource::RequestType requestType;
QString who = name;
- if (name.startsWith("TimelineWithFriends:")) {
+ if (name.startsWith(timelineWithFriendsPrefix)) {
requestType = TimelineSource::TimelineWithFriends;
- who.remove("TimelineWithFriends:");
- } else if (name.startsWith("Profile:")) {
+ who.remove(timelineWithFriendsPrefix);
+ } else if (name.startsWith(profilePrefix)) {
requestType = TimelineSource::Profile;
- who.remove("Profile:");
+ who.remove(profilePrefix);
}else{
requestType = TimelineSource::Timeline;
- who.remove("Timeline:");
+ who.remove(timelinePrefix);
}
TimelineSource *source = dynamic_cast<TimelineSource*>(containerForSource(name));
Index: dataengines/twitter/twitterengine.h
===================================================================
--- dataengines/twitter/twitterengine.h (Revision 911365)
+++ dataengines/twitter/twitterengine.h (Arbeitskopie)
@@ -65,6 +65,12 @@
protected slots:
bool updateSourceEvent(const QString &name);
+
+ private:
+ static const QString timelinePrefix;
+ static const QString timelineWithFriendsPrefix;
+ static const QString profilePrefix;
+
};
K_EXPORT_PLASMA_DATAENGINE(twitter, TwitterEngine)
Index: dataengines/comic/comicproviderwrapper.cpp
===================================================================
--- dataengines/comic/comicproviderwrapper.cpp (Revision 911365)
+++ dataengines/comic/comicproviderwrapper.cpp (Arbeitskopie)
@@ -257,7 +257,7 @@
void ComicProviderWrapper::init()
{
- const QString path = KStandardDirs::locate( "data", "plasma/comics/" + mProvider->pluginName() + "/" );
+ const QString path = KStandardDirs::locate( "data", "plasma/comics/" + mProvider->pluginName() + '/' );
if ( !path.isEmpty() ) {
mPackage = new Plasma::Package( path, ComicProviderKross::packageStructure() );
@@ -298,8 +298,8 @@
foreach( const QString &interpretername, Kross::Manager::self().interpreters() ) {
info = Kross::Manager::self().interpreterInfo( interpretername );
wildcards = info->wildcard();
- wildcards.replace( "*", "" );
- mExtensions << wildcards.split( " " );
+ wildcards.replace( '*', "" );
+ mExtensions << wildcards.split( ' ' );
}
}
return mExtensions;
Index: dataengines/comic/comicproviderwrapper.h
===================================================================
--- dataengines/comic/comicproviderwrapper.h (Revision 911365)
+++ dataengines/comic/comicproviderwrapper.h (Arbeitskopie)
@@ -38,7 +38,7 @@
Q_PROPERTY( QImage image READ image WRITE setImage )
Q_PROPERTY( QByteArray rawData READ rawData WRITE setRawData )
public:
- ImageWrapper( QObject *parent = 0, const QImage &image = QImage() );
+ explicit ImageWrapper( QObject *parent = 0, const QImage &image = QImage() );
QImage image() const;
void setImage( const QImage &image );
@@ -54,7 +54,7 @@
Q_OBJECT
Q_PROPERTY( QDate date READ date WRITE setDate )
public:
- DateWrapper( QObject *parent = 0, const QDate &date = QDate() );
+ explicit DateWrapper( QObject *parent = 0, const QDate &date = QDate() );
QDate date() const;
void setDate( const QDate &date );
Index: dataengines/comic/cachedprovider.cpp
===================================================================
--- dataengines/comic/cachedprovider.cpp (Revision 911365)
+++ dataengines/comic/cachedprovider.cpp (Arbeitskopie)
@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "cachedprovider.h"
+
#include <QtCore/QFile>
#include <QtCore/QSettings>
#include <QtCore/QTimer>
@@ -24,7 +26,6 @@
#include <kstandarddirs.h>
#include <KUrl>
-#include "cachedprovider.h"
static QString identifierToPath( const QString &identifier )
{
Index: dataengines/comic/cachedprovider.h
===================================================================
--- dataengines/comic/cachedprovider.h (Revision 911365)
+++ dataengines/comic/cachedprovider.h (Arbeitskopie)
@@ -37,7 +37,7 @@
* @param identifier The identifier of the cached comic.
* @param parent The parent object.
*/
- CachedProvider( QObject *parent, const QVariantList &args = QVariantList() );
+ explicit CachedProvider( QObject *parent, const QVariantList &args = QVariantList() );
/**
* Destroys the cached provider.
Index: dataengines/comic/comic.cpp
===================================================================
--- dataengines/comic/comic.cpp (Revision 911365)
+++ dataengines/comic/comic.cpp (Arbeitskopie)
@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "comic.h"
+
#include <QtCore/QDate>
#include <QtCore/QFileInfo>
#include <QtCore/QSettings>
@@ -26,8 +28,6 @@
#include <solid/networking.h>
-#include "comic.h"
-
#include "cachedprovider.h"
ComicEngine::ComicEngine( QObject* parent, const QVariantList& args )
_______________________________________________
Plasma-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/plasma-devel