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

korganizer

  • sources
  • kde-4.12
  • 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 #include "theme.moc"
35 
36 using namespace KOrg;
37 
38 void Theme::useThemeFrom( const KUrl &url )
39 {
40  if ( url.isEmpty() ) {
41  return;
42  }
43 
44  if( !url.isLocalFile() ) {
45  kDebug() << "can't import (1) : only local files are supported" << url.prettyUrl();
46  return;
47  }
48 
49  QFile *file = new QFile( url.toLocalFile() );
50  kDebug() << file->fileName();
51  if ( !file->open( QFile::ReadOnly | QFile::Text ) ) {
52  //TODO: KMessageBox "invalid file"
53  kDebug() << "can't import: invalid file: (1)" << url.toLocalFile();
54  delete file;
55  return;
56  }
57 
58  KMimeType::Ptr mimeType;
59  mimeType = KMimeType::findByUrl( url );
60 
61  if ( mimeType->name() == "application/zip" ) {
62  KZip *zip = new KZip( url.toLocalFile() );
63 
64  if ( !zip->open( QIODevice::ReadOnly ) ) {
65  //TODO: KMessageBox "invalid file"
66  kDebug() << "can't import: invalid file: (3)" << url.toLocalFile();
67  delete zip;
68  delete file;
69  return;
70  }
71 
72  const KArchiveDirectory *dir = zip->directory();
73  if ( dir == 0 ) {
74  //TODO: KMessageBox "invalid file"
75  kDebug() << "can't import: invalid file: (4)" << url.toLocalFile();
76  delete zip;
77  delete file;
78  return;
79  }
80 
81  if ( ! KIO::NetAccess::del( KUrl::fromPath( storageDir().absolutePath() ),
82  0 ) ) {
83  kWarning() << "could not delete stale theme files";
84  }
85  dir->copyTo( storageDir().path() );
86 
87  delete file;
88 
89  file = new QFile( storageDir().path() + "/theme.xml" );
90 
91  if ( !file->open( QFile::ReadOnly | QFile::Text ) ) {
92  //TODO: KMessageBox "invalid file"
93  kDebug() << "can't import: invalid file: (5)" << url.toLocalFile();
94  delete file;
95  delete zip;
96  return;
97  }
98 
99  KMimeType::Ptr mimeType;
100  mimeType = KMimeType::findByUrl( storageDir().path() + "/theme.xml" );
101  if ( mimeType->name() != "application/xml" ) {
102  //TODO: KMessageBox "invalid file"
103  kDebug() << "can't import: invalid file: (6)" << url.toLocalFile();
104  delete zip;
105  delete file;
106  return;
107  }
108  } else if ( mimeType->name() == "application/xml" ) {
109  KIO::NetAccess::file_copy( url.toLocalFile(), storageDir().path() + '/', 0 );
110  delete file;
111  } else {
112  //TODO: KMessageBox "invalid file"
113  kDebug() << "can't import: invalid file: (2)" << url.toLocalFile();
114  delete file;
115  return;
116  }
117 
118  clearCurrentTheme();
119  ThemeImporter reader( file );
120 }
121 
122 void Theme::saveThemeTo( const KUrl &url )
123 {
124  const QString path = url.isLocalFile() ? url.toLocalFile() : url.path();
125 
126  KZip *zip = new KZip( path );
127 
128  if ( ! zip->open( QIODevice::WriteOnly ) ) {
129  //TODO: KMessageBox "no write permission"
130  kDebug() << "can't export: no write permission:" << path;
131  return;
132  }
133  if ( ! zip->addLocalDirectory( storageDir().absolutePath(), QString() ) ) {
134  //TODO: KMessageBox "could not add theme files"
135  kDebug() << "can't export: could not add theme files to:" << path;
136  return;
137  }
138  if ( ! zip->close() ) {
139  //TODO: KMessageBox "could not write theme file"
140  kDebug() << "can't export: could not close theme file:" << path;
141  return;
142  }
143 }
144 
145 void Theme::clearCurrentTheme()
146 {
147  foreach ( const QString &viewType, Theme::themableViews() ) {
148  KSharedConfig::Ptr conf = KSharedConfig::openConfig();
149  KConfigGroup( conf, "Theme/" + viewType + " view" ).deleteGroup();
150  }
151 }
152 
153 const QDir Theme::storageDir()
154 {
155  QDir *dir = new QDir( KStandardDirs::locateLocal( "appdata", "theme" ) );
156  return *dir;
157 }
158 
159 const QStringList Theme::themableViews( const QString &viewType )
160 {
161  QStringList l;
162  l.append( "Agenda" );
163  l.append( "Month" );
164  // TODO: TodoView?
165  if ( l.contains( viewType ) ) {
166  return QStringList( viewType );
167  } else if ( viewType.isEmpty() ) {
168  return l;
169  } else {
170  return QStringList();
171  }
172 }
KOrg::ThemeImporter
Class to import an XML theme file's settings into KOrganizer's KConfig-based configuration file...
Definition: themeimporter.h:38
KOrg::Theme::clearCurrentTheme
static void clearCurrentTheme()
Clear the current theme settings.
Definition: theme.cpp:145
KOrg::Theme::themableViews
static const QStringList themableViews(const QString &viewType=QString())
Return all themable views corresponding to the viewType.
Definition: theme.cpp:159
KOrg::Theme::saveThemeTo
static void saveThemeTo(const KUrl &url)
Save the current theme settings to a theme file.
Definition: theme.cpp:122
theme.h
KOrg::Theme::storageDir
static const QDir storageDir()
Return the directory where the current theme is stored.
Definition: theme.cpp:153
koprefs.h
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:38
themeimporter.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 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

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