• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.14
  • kdepim
  • korganizer
  • themes
theme.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2007 Loïc Corbasson <loic.corbasson@gmail.com>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "theme.h"
23 #include "themeimporter.h"
24 #include "koprefs.h"
25 
26 #include <KIO/NetAccess>
27 #include <KDebug>
28 #include <KMimeType>
29 #include <KStandardDirs>
30 #include <KZip>
31 
32 #include <QtCore/QFile>
33 
34 
35 using namespace KOrg;
36 
37 void Theme::useThemeFrom( const KUrl &url )
38 {
39  if ( url.isEmpty() ) {
40  return;
41  }
42 
43  if( !url.isLocalFile() ) {
44  kDebug() << "can't import (1) : only local files are supported" << url.prettyUrl();
45  return;
46  }
47 
48  QFile *file = new QFile( url.toLocalFile() );
49  kDebug() << file->fileName();
50  if ( !file->open( QFile::ReadOnly | QFile::Text ) ) {
51  //TODO: KMessageBox "invalid file"
52  kDebug() << "can't import: invalid file: (1)" << url.toLocalFile();
53  delete file;
54  return;
55  }
56 
57  KMimeType::Ptr mimeType;
58  mimeType = KMimeType::findByUrl( url );
59 
60  if ( mimeType->name() == "application/zip" ) {
61  KZip *zip = new KZip( url.toLocalFile() );
62 
63  if ( !zip->open( QIODevice::ReadOnly ) ) {
64  //TODO: KMessageBox "invalid file"
65  kDebug() << "can't import: invalid file: (3)" << url.toLocalFile();
66  delete zip;
67  delete file;
68  return;
69  }
70 
71  const KArchiveDirectory *dir = zip->directory();
72  if ( dir == 0 ) {
73  //TODO: KMessageBox "invalid file"
74  kDebug() << "can't import: invalid file: (4)" << url.toLocalFile();
75  delete zip;
76  delete file;
77  return;
78  }
79 
80  if ( ! KIO::NetAccess::del( KUrl::fromPath( storageDir().absolutePath() ),
81  0 ) ) {
82  kWarning() << "could not delete stale theme files";
83  }
84  dir->copyTo( storageDir().path() );
85 
86  delete file;
87 
88  file = new QFile( storageDir().path() + "/theme.xml" );
89 
90  if ( !file->open( QFile::ReadOnly | QFile::Text ) ) {
91  //TODO: KMessageBox "invalid file"
92  kDebug() << "can't import: invalid file: (5)" << url.toLocalFile();
93  delete file;
94  delete zip;
95  return;
96  }
97 
98  KMimeType::Ptr mimeType;
99  mimeType = KMimeType::findByUrl( storageDir().path() + "/theme.xml" );
100  if ( mimeType->name() != "application/xml" ) {
101  //TODO: KMessageBox "invalid file"
102  kDebug() << "can't import: invalid file: (6)" << url.toLocalFile();
103  delete zip;
104  delete file;
105  return;
106  }
107  } else if ( mimeType->name() == "application/xml" ) {
108  KIO::NetAccess::file_copy( url.toLocalFile(), storageDir().path() + '/', 0 );
109  delete file;
110  } else {
111  //TODO: KMessageBox "invalid file"
112  kDebug() << "can't import: invalid file: (2)" << url.toLocalFile();
113  delete file;
114  return;
115  }
116 
117  clearCurrentTheme();
118  ThemeImporter reader( file );
119 }
120 
121 void Theme::saveThemeTo( const KUrl &url )
122 {
123  const QString path = url.isLocalFile() ? url.toLocalFile() : url.path();
124 
125  KZip *zip = new KZip( path );
126 
127  if ( ! zip->open( QIODevice::WriteOnly ) ) {
128  //TODO: KMessageBox "no write permission"
129  kDebug() << "can't export: no write permission:" << path;
130  return;
131  }
132  if ( ! zip->addLocalDirectory( storageDir().absolutePath(), QString() ) ) {
133  //TODO: KMessageBox "could not add theme files"
134  kDebug() << "can't export: could not add theme files to:" << path;
135  return;
136  }
137  if ( ! zip->close() ) {
138  //TODO: KMessageBox "could not write theme file"
139  kDebug() << "can't export: could not close theme file:" << path;
140  return;
141  }
142 }
143 
144 void Theme::clearCurrentTheme()
145 {
146  foreach ( const QString &viewType, Theme::themableViews() ) {
147  KSharedConfig::Ptr conf = KSharedConfig::openConfig();
148  KConfigGroup( conf, "Theme/" + viewType + " view" ).deleteGroup();
149  }
150 }
151 
152 const QDir Theme::storageDir()
153 {
154  QDir *dir = new QDir( KStandardDirs::locateLocal( "appdata", "theme" ) );
155  return *dir;
156 }
157 
158 const QStringList Theme::themableViews( const QString &viewType )
159 {
160  QStringList l;
161  l.append( "Agenda" );
162  l.append( "Month" );
163  // TODO: TodoView?
164  if ( l.contains( viewType ) ) {
165  return QStringList( viewType );
166  } else if ( viewType.isEmpty() ) {
167  return l;
168  } else {
169  return QStringList();
170  }
171 }
KOrg::ThemeImporter
Class to import an XML theme file's settings into KOrganizer's KConfig-based configuration file...
Definition: themeimporter.h:37
KOrg::Theme::clearCurrentTheme
static void clearCurrentTheme()
Clear the current theme settings.
Definition: theme.cpp:144
QFile::fileName
QString fileName() const
KOrg::Theme::themableViews
static const QStringList themableViews(const QString &viewType=QString())
Return all themable views corresponding to the viewType.
Definition: theme.cpp:158
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KOrg::Theme::saveThemeTo
static void saveThemeTo(const KUrl &url)
Save the current theme settings to a theme file.
Definition: theme.cpp:121
theme.h
KOrg::Theme::storageDir
static const QDir storageDir()
Return the directory where the current theme is stored.
Definition: theme.cpp:152
QFile
QList::append
void append(const T &value)
QDir::path
QString path() const
koprefs.h
QString::isEmpty
bool isEmpty() const
QString
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QStringList
KOrg::Theme::useThemeFrom
static void useThemeFrom(const KUrl &url)
Import settings from a theme at the specified URL into KOrganizer's config.
Definition: theme.cpp:37
QDir
themeimporter.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal