33 #include <KCalCore/FileStorage>
34 #include <KCalCore/ICalFormat>
35 #include <KCalCore/MemoryCalendar>
37 #include <KFileDialog>
38 #include <KMessageBox>
39 #include <KStandardDirs>
40 #include <KIO/NetAccess>
43 #include <QVBoxLayout>
46 :
KDialog( parent ), mOriginalUrl( url ), mFileStorage( 0 )
48 setCaption( i18n(
"Import Calendar/Event" ) );
50 setButtons( User1 | User2 | Cancel );
51 setDefaultButton( User1 );
53 QVBoxLayout *topLayout =
new QVBoxLayout( topFrame );
54 topLayout->setSpacing( spacingHint() );
55 topLayout->setMargin( 0 );
58 KCalCore::MemoryCalendar::Ptr(
61 mListView =
new KOListView( Akonadi::ETMCalendar::Ptr(),
this,
true );
62 topLayout->addWidget( mListView );
64 topLayout->setSpacing( spacingHint() );
65 topLayout->setMargin( marginHint() );
67 connect(
this, SIGNAL(user1Clicked()), SLOT(
slotMerge()) );
68 connect(
this, SIGNAL(user2Clicked()), SLOT(
slotAdd()) );
73 setButtonGuiItem( User2, KGuiItem( i18n(
"&Add as new calendar..." ), QLatin1String(
"add") ) );
75 setButtonGuiItem( User2, KGuiItem( i18n(
"&Add as new calendar" ), QLatin1String(
"add") ) );
83 if ( mLocalUrl && !mOriginalUrl.isLocalFile() ) {
84 KIO::NetAccess::removeTempFile( mLocalUrl->path() );
94 if ( !mOriginalUrl.isLocalFile() ) {
97 KIO::NetAccess::removeTempFile( mLocalUrl->path() );
102 if ( KIO::NetAccess::download( mOriginalUrl, tmpFile, 0 ) ) {
103 mLocalUrl =
new KUrl( tmpFile );
108 mLocalUrl = &mOriginalUrl;
112 mFileStorage =
new KCalCore::FileStorage( mCalendar,
114 new KCalCore::ICalFormat() );
116 const bool success = mFileStorage->load();
118 if ( !success && !mOriginalUrl.isLocalFile() ) {
119 KIO::NetAccess::removeTempFile( mLocalUrl->path() );
132 emit
openURL( *mLocalUrl,
true );
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" ) );
147 finalUrl = KUrl( fileName );
149 if ( !KIO::NetAccess::file_copy( mOriginalUrl, finalUrl,
this ) &&
150 KIO::NetAccess::lastError() ) {
151 KMessageBox::error(
this, KIO::NetAccess::lastErrorString() );
156 if ( finalUrl.isValid() ) {
163 bool PreviewDialog::isTempFile()
const
165 return mOriginalUrl.path().startsWith( KStandardDirs::locateLocal(
"tmp", QLatin1String(
"") ) );
168 #include "previewdialog.moc"
void dialogFinished(PreviewDialog *)
void openURL(const KUrl &, bool)
void addResource(const KUrl &)
static KOPrefs * instance()
Get instance of KOPrefs.
PreviewDialog(const KUrl &url, QWidget *parent)