You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.2 KiB
128 lines
3.2 KiB
#include <kglobal.h>
|
|
#include <tqfileinfo.h>
|
|
#include <tqregexp.h>
|
|
#include <kstandarddirs.h>
|
|
#include <tqdir.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() {
|
|
}
|
|
|
|
TQStringList WaSkinManager::availableSkins() {
|
|
TQStringList skinDirs = TDEGlobal::dirs()->findDirs("data", "noatun/skins/winamp");
|
|
TQStringList skin_list;
|
|
|
|
// This loop adds them all to our skin list
|
|
for(unsigned int x = 0;x < skinDirs.count();x++) {
|
|
TQDir skinTQDir(skinDirs[x]);
|
|
|
|
// We only want directories, although there shouldn't be anything else
|
|
skinTQDir.setFilter( TQDir::Dirs );
|
|
// I guess name is as good as any
|
|
skinTQDir.setSorting( TQDir::Name );
|
|
|
|
for (unsigned int y = 0;y < skinTQDir.count();y++) {
|
|
TQStringList skins = skinTQDir.entryList(TQDir::Dirs, TQDir::Name);
|
|
|
|
// We really don't care for '.' and '..'
|
|
if (skinTQDir[y][0] != (char)'.') {
|
|
// Add ourselves to the list, using our directory name
|
|
skin_list += skinTQDir[y];
|
|
}
|
|
}
|
|
}
|
|
|
|
return skin_list;
|
|
}
|
|
|
|
TQString WaSkinManager::currentSkin() {
|
|
return mCurrentSkin;
|
|
}
|
|
|
|
TQString WaSkinManager::defaultSkin() {
|
|
return "Winamp";
|
|
}
|
|
|
|
bool WaSkinManager::loadSkin(TQString skinName) {
|
|
TQStringList skins = TDEGlobal::dirs()->findDirs("data", "noatun/skins/winamp/" + skinName);
|
|
|
|
if (!skins.count())
|
|
mCurrentSkin = defaultSkin();
|
|
else
|
|
mCurrentSkin = skinName;
|
|
|
|
return _waskinmodel_instance->load(skins[0]);
|
|
}
|
|
|
|
bool WaSkinManager::installSkin(TQString _url) {
|
|
TQString location = TDEGlobal::dirs()->saveLocation("data", "noatun/skins/winamp");
|
|
KURL url(_url);
|
|
TQString mimetype = KMimeType::findByURL(_url)->name();
|
|
|
|
if (mimetype == "inode/directory")
|
|
{
|
|
KIO::Job *job = KIO::copy(url, location, !url.isLocalFile());
|
|
connect(job, TQT_SIGNAL(result(KIO::Job *)), this, TQT_SIGNAL(updateSkinList()));
|
|
return true;
|
|
}
|
|
else if ((mimetype == "interface/x-winamp-skin") || (mimetype == "application/x-zip"))
|
|
{
|
|
if (!url.isLocalFile())
|
|
return false;
|
|
|
|
TQString base_path;
|
|
base_path = location + "/" + TQFileInfo(url.path()).baseName().replace(TQRegExp("_"), " ");
|
|
KIO::Job *job = KIO::copy("zip:" + url.path(), base_path);
|
|
connect(job, TQT_SIGNAL(result(KIO::Job *)), this, TQT_SIGNAL(updateSkinList()));
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool WaSkinManager::removeSkin(TQString skinName) {
|
|
if (!skinRemovable(skinName))
|
|
return false;
|
|
|
|
TQStringList skins = TDEGlobal::dirs()->findDirs("data", "noatun/skins/winamp/" + skinName);
|
|
|
|
KIO::Job *job = KIO::del(KURL(skins[0]), false, false);
|
|
connect(job, TQT_SIGNAL(result(KIO::Job *)), this, TQT_SIGNAL(updateSkinList()));
|
|
|
|
return true;
|
|
}
|
|
|
|
bool WaSkinManager::skinRemovable(TQString skinName) {
|
|
TQStringList skins = TDEGlobal::dirs()->findDirs("data", "noatun/skins/winamp/" + skinName);
|
|
|
|
if (!skins.count())
|
|
return false;
|
|
|
|
TQFileInfo info(skins[0]);
|
|
return info.isWritable();
|
|
}
|
|
|
|
TQStringList WaSkinManager::skinMimeTypes() {
|
|
TQStringList temp;
|
|
|
|
temp.append("interface/x-winamp-skin");
|
|
temp.append("application/x-zip");
|
|
temp.append("inode/directory");
|
|
|
|
return temp;
|
|
}
|
|
|
|
#include "waSkinManager.moc"
|