summaryrefslogtreecommitdiffstats
path: root/noatun/modules/winskin/waSkinManager.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite2de64d6f1beb9e492daf5b886e19933c1fa41dd (patch)
tree9047cf9e6b5c43878d5bf82660adae77ceee097a /noatun/modules/winskin/waSkinManager.cpp
downloadtdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.tar.gz
tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'noatun/modules/winskin/waSkinManager.cpp')
-rw-r--r--noatun/modules/winskin/waSkinManager.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/noatun/modules/winskin/waSkinManager.cpp b/noatun/modules/winskin/waSkinManager.cpp
new file mode 100644
index 00000000..5cde117b
--- /dev/null
+++ b/noatun/modules/winskin/waSkinManager.cpp
@@ -0,0 +1,127 @@
+#include <kglobal.h>
+#include <qfileinfo.h>
+#include <qregexp.h>
+#include <kstandarddirs.h>
+#include <qdir.h>
+#include <kdebug.h>
+#include <kmimetype.h>
+#include <kio/job.h>
+#include <kurl.h>
+#include <kio/netaccess.h>
+#include <kzip.h>
+
+#include "waSkinManager.h"
+#include "waSkinModel.h"
+
+WaSkinManager::WaSkinManager() : DCOPObject("WaSkinManager") {
+}
+
+WaSkinManager::~WaSkinManager() {
+}
+
+QStringList WaSkinManager::availableSkins() {
+ QStringList skinDirs = KGlobal::dirs()->findDirs("data", "noatun/skins/winamp");
+ QStringList skin_list;
+
+ // This loop adds them all to our skin list
+ for(unsigned int x = 0;x < skinDirs.count();x++) {
+ QDir skinQDir(skinDirs[x]);
+
+ // We only want directories, although there shouldn't be anything else
+ skinQDir.setFilter( QDir::Dirs );
+ // I guess name is as good as any
+ skinQDir.setSorting( QDir::Name );
+
+ for (unsigned int y = 0;y < skinQDir.count();y++) {
+ QStringList skins = skinQDir.entryList(QDir::Dirs, QDir::Name);
+
+ // We really don't care for '.' and '..'
+ if (skinQDir[y][0] != (char)'.') {
+ // Add ourselves to the list, using our directory name
+ skin_list += skinQDir[y];
+ }
+ }
+ }
+
+ return skin_list;
+}
+
+QString WaSkinManager::currentSkin() {
+ return mCurrentSkin;
+}
+
+QString WaSkinManager::defaultSkin() {
+ return "Winamp";
+}
+
+bool WaSkinManager::loadSkin(QString skinName) {
+ QStringList skins = KGlobal::dirs()->findDirs("data", "noatun/skins/winamp/" + skinName);
+
+ if (!skins.count())
+ mCurrentSkin = defaultSkin();
+ else
+ mCurrentSkin = skinName;
+
+ return _waskinmodel_instance->load(skins[0]);
+}
+
+bool WaSkinManager::installSkin(QString _url) {
+ QString location = KGlobal::dirs()->saveLocation("data", "noatun/skins/winamp");
+ KURL url(_url);
+ QString mimetype = KMimeType::findByURL(_url)->name();
+
+ if (mimetype == "inode/directory")
+ {
+ KIO::Job *job = KIO::copy(url, location, !url.isLocalFile());
+ connect(job, SIGNAL(result(KIO::Job *)), this, SIGNAL(updateSkinList()));
+ return true;
+ }
+ else if ((mimetype == "interface/x-winamp-skin") || (mimetype == "application/x-zip"))
+ {
+ if (!url.isLocalFile())
+ return false;
+
+ QString base_path;
+ base_path = location + "/" + QFileInfo(url.path()).baseName().replace(QRegExp("_"), " ");
+ KIO::Job *job = KIO::copy("zip:" + url.path(), base_path);
+ connect(job, SIGNAL(result(KIO::Job *)), this, SIGNAL(updateSkinList()));
+
+ return true;
+ }
+
+ return false;
+}
+
+bool WaSkinManager::removeSkin(QString skinName) {
+ if (!skinRemovable(skinName))
+ return false;
+
+ QStringList skins = KGlobal::dirs()->findDirs("data", "noatun/skins/winamp/" + skinName);
+
+ KIO::Job *job = KIO::del(KURL(skins[0]), false, false);
+ connect(job, SIGNAL(result(KIO::Job *)), this, SIGNAL(updateSkinList()));
+
+ return true;
+}
+
+bool WaSkinManager::skinRemovable(QString skinName) {
+ QStringList skins = KGlobal::dirs()->findDirs("data", "noatun/skins/winamp/" + skinName);
+
+ if (!skins.count())
+ return false;
+
+ QFileInfo info(skins[0]);
+ return info.isWritable();
+}
+
+QStringList WaSkinManager::skinMimeTypes() {
+ QStringList temp;
+
+ temp.append("interface/x-winamp-skin");
+ temp.append("application/x-zip");
+ temp.append("inode/directory");
+
+ return temp;
+}
+
+#include "waSkinManager.moc"