26 #include <KIO/NetAccess>
29 #include <KStandardDirs>
32 #include <QtCore/QFile>
40 if ( url.isEmpty() ) {
44 if( !url.isLocalFile() ) {
45 kDebug() <<
"can't import (1) : only local files are supported" << url.prettyUrl();
49 QFile *file =
new QFile( url.toLocalFile() );
50 kDebug() << file->fileName();
51 if ( !file->open( QFile::ReadOnly | QFile::Text ) ) {
53 kDebug() <<
"can't import: invalid file: (1)" << url.toLocalFile();
58 KMimeType::Ptr mimeType;
59 mimeType = KMimeType::findByUrl( url );
61 if ( mimeType->name() ==
"application/zip" ) {
62 KZip *zip =
new KZip( url.toLocalFile() );
64 if ( !zip->open( QIODevice::ReadOnly ) ) {
66 kDebug() <<
"can't import: invalid file: (3)" << url.toLocalFile();
72 const KArchiveDirectory *dir = zip->directory();
75 kDebug() <<
"can't import: invalid file: (4)" << url.toLocalFile();
81 if ( ! KIO::NetAccess::del( KUrl::fromPath(
storageDir().absolutePath() ),
83 kWarning() <<
"could not delete stale theme files";
89 file =
new QFile(
storageDir().path() +
"/theme.xml" );
91 if ( !file->open( QFile::ReadOnly | QFile::Text ) ) {
93 kDebug() <<
"can't import: invalid file: (5)" << url.toLocalFile();
99 KMimeType::Ptr mimeType;
100 mimeType = KMimeType::findByUrl(
storageDir().path() +
"/theme.xml" );
101 if ( mimeType->name() !=
"application/xml" ) {
103 kDebug() <<
"can't import: invalid file: (6)" << url.toLocalFile();
108 }
else if ( mimeType->name() ==
"application/xml" ) {
109 KIO::NetAccess::file_copy( url.toLocalFile(),
storageDir().path() +
'/', 0 );
113 kDebug() <<
"can't import: invalid file: (2)" << url.toLocalFile();
124 const QString path = url.isLocalFile() ? url.toLocalFile() : url.path();
126 KZip *zip =
new KZip( path );
128 if ( ! zip->open( QIODevice::WriteOnly ) ) {
130 kDebug() <<
"can't export: no write permission:" << path;
133 if ( ! zip->addLocalDirectory(
storageDir().absolutePath(), QString() ) ) {
135 kDebug() <<
"can't export: could not add theme files to:" << path;
138 if ( ! zip->close() ) {
140 kDebug() <<
"can't export: could not close theme file:" << path;
148 KSharedConfig::Ptr conf = KSharedConfig::openConfig();
149 KConfigGroup( conf,
"Theme/" + viewType +
" view" ).deleteGroup();
155 QDir *dir =
new QDir( KStandardDirs::locateLocal(
"appdata",
"theme" ) );
162 l.append(
"Agenda" );
165 if ( l.contains( viewType ) ) {
166 return QStringList( viewType );
167 }
else if ( viewType.isEmpty() ) {
170 return QStringList();
Class to import an XML theme file's settings into KOrganizer's KConfig-based configuration file...
static void clearCurrentTheme()
Clear the current theme settings.
static const QStringList themableViews(const QString &viewType=QString())
Return all themable views corresponding to the viewType.
static void saveThemeTo(const KUrl &url)
Save the current theme settings to a theme file.
static const QDir storageDir()
Return the directory where the current theme is stored.
static void useThemeFrom(const KUrl &url)
Import settings from a theme at the specified URL into KOrganizer's config.