• 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
previewdialog.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
8  Author: Sergio Martins, <sergio.martins@kdab.com>
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 
24  As a special exception, permission is given to link this program
25  with any edition of Qt, and distribute the resulting executable,
26  without including the source code for Qt in the source distribution.
27 */
28 
29 #include "previewdialog.h"
30 #include "koprefs.h"
31 #include "views/listview/kolistview.h"
32 
33 #include <KCalCore/FileStorage>
34 #include <KCalCore/ICalFormat>
35 #include <KCalCore/MemoryCalendar>
36 
37 #include <KFileDialog>
38 #include <KMessageBox>
39 #include <KStandardDirs>
40 #include <KIO/NetAccess>
41 
42 #include <QFrame>
43 #include <QVBoxLayout>
44 
45 PreviewDialog::PreviewDialog( const KUrl &url, QWidget *parent )
46  : KDialog( parent ), mOriginalUrl( url ), mFileStorage( 0 )
47 {
48  setCaption( i18n( "Import Calendar/Event" ) );
49  // KGuiItem( i18n("&Merge into existing calendar"), "merge" )
50  setButtons( User1 | User2 | Cancel );
51  setDefaultButton( User1 );
52  QFrame *topFrame = new QFrame( this );
53  QVBoxLayout *topLayout = new QVBoxLayout( topFrame );
54  topLayout->setSpacing( spacingHint() );
55  topLayout->setMargin( 0 );
56 
57  mCalendar =
58  KCalCore::MemoryCalendar::Ptr(
59  new KCalCore::MemoryCalendar( KOPrefs::instance()->mTimeZoneId ) );
60 
61  mListView = new KOListView( Akonadi::ETMCalendar::Ptr(), this, true );
62  topLayout->addWidget( mListView );
63 
64  topLayout->setSpacing( spacingHint() );
65  topLayout->setMargin( marginHint() );
66 
67  connect( this, SIGNAL(user1Clicked()), SLOT(slotMerge()) );
68  connect( this, SIGNAL(user2Clicked()), SLOT(slotAdd()) );
69 
70  // when someone edits a kmail attachment he's editing a tmp file, check for that
71  // and if it's a tmp file then open a save dialog
72  if ( isTempFile() ) {
73  setButtonGuiItem( User2, KGuiItem( i18n( "&Add as new calendar..." ), QLatin1String("add") ) );
74  } else {
75  setButtonGuiItem( User2, KGuiItem( i18n( "&Add as new calendar" ), QLatin1String("add") ) );
76  }
77 
78  mLocalUrl = 0;
79 }
80 
81 PreviewDialog::~PreviewDialog()
82 {
83  if ( mLocalUrl && !mOriginalUrl.isLocalFile() ) {
84  KIO::NetAccess::removeTempFile( mLocalUrl->path() );
85  delete mLocalUrl;
86  }
87 
88  delete mFileStorage;
89 }
90 
91 bool PreviewDialog::loadCalendar()
92 {
93  // If it's a remote file, download it so we can give it to CalendarLocal
94  if ( !mOriginalUrl.isLocalFile() ) {
95  if ( mLocalUrl ) {
96  // loadCalendar already called.. remove old one.
97  KIO::NetAccess::removeTempFile( mLocalUrl->path() );
98  delete mLocalUrl;
99  }
100 
101  QString tmpFile;
102  if ( KIO::NetAccess::download( mOriginalUrl, tmpFile, 0 ) ) {
103  mLocalUrl = new KUrl( tmpFile );
104  } else {
105  mLocalUrl = 0;
106  }
107  } else {
108  mLocalUrl = &mOriginalUrl;
109  }
110 
111  if ( mLocalUrl ) {
112  mFileStorage = new KCalCore::FileStorage( mCalendar,
113  mLocalUrl->path(),
114  new KCalCore::ICalFormat() );
115 
116  const bool success = mFileStorage->load();
117 
118  if ( !success && !mOriginalUrl.isLocalFile() ) {
119  KIO::NetAccess::removeTempFile( mLocalUrl->path() );
120  } else {
121  mListView->showAll();
122  }
123  return success;
124  } else {
125  return false;
126  }
127 }
128 
129 void PreviewDialog::slotMerge()
130 {
131  if ( mLocalUrl ) {
132  emit openURL( *mLocalUrl, true );
133  emit dialogFinished( this );
134  accept();
135  }
136 }
137 
138 void PreviewDialog::slotAdd()
139 {
140  KUrl finalUrl = mOriginalUrl;
141  if ( isTempFile() ) {
142  const QString fileName =
143  KFileDialog::getSaveFileName( KStandardDirs::locateLocal( "data",QLatin1String("korganizer/") ),
144  i18n( "*.vcs *.ics|Calendar Files" ),
145  this, i18n( "Select path for new calendar" ) );
146 
147  finalUrl = KUrl( fileName );
148 
149  if ( !KIO::NetAccess::file_copy( mOriginalUrl, finalUrl, this ) &&
150  KIO::NetAccess::lastError() ) {
151  KMessageBox::error( this, KIO::NetAccess::lastErrorString() );
152  return;
153  }
154  }
155 
156  if ( finalUrl.isValid() ) {
157  emit addResource( finalUrl );
158  emit dialogFinished( this );
159  accept();
160  }
161 }
162 
163 bool PreviewDialog::isTempFile() const
164 {
165  return mOriginalUrl.path().startsWith( KStandardDirs::locateLocal( "tmp", QLatin1String("") ) );
166 }
167 
168 #include "previewdialog.moc"
kolistview.h
PreviewDialog::dialogFinished
void dialogFinished(PreviewDialog *)
PreviewDialog::openURL
void openURL(const KUrl &, bool)
PreviewDialog::addResource
void addResource(const KUrl &)
QWidget
KDialog
koprefs.h
PreviewDialog::~PreviewDialog
~PreviewDialog()
Definition: previewdialog.cpp:81
previewdialog.h
KOListView
Definition: kolistview.h:44
PreviewDialog::loadCalendar
bool loadCalendar()
Definition: previewdialog.cpp:91
KOListView::showAll
void showAll()
Definition: kolistview.cpp:154
KOPrefs::instance
static KOPrefs * instance()
Get instance of KOPrefs.
Definition: koprefs.cpp:68
PreviewDialog::slotAdd
void slotAdd()
Definition: previewdialog.cpp:138
QFrame
PreviewDialog::slotMerge
void slotMerge()
Definition: previewdialog.cpp:129
PreviewDialog::PreviewDialog
PreviewDialog(const KUrl &url, QWidget *parent)
Definition: previewdialog.cpp:45
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