29 #include "previewdialog.h"
31 #include "kolistview.h"
33 #include "stdcalendar.h"
35 #include <tdelocale.h>
37 #include <libkcal/calendarlocal.h>
39 #include <kstandarddirs.h>
40 #include <tdefiledialog.h>
41 #include <tdemessagebox.h>
42 #include <tdeio/netaccess.h>
46 #include <tqradiobutton.h>
47 #include <tqpushbutton.h>
52 PreviewDialog::PreviewDialog(
const KURL &url, TQWidget *parent )
53 : KDialogBase( Plain, i18n(
"Import Calendar/Event"), User1 | User2 | Cancel, User1, parent,
54 0, true, true, KGuiItem( i18n(
"&Merge into existing calendar"),
"merge" ) ),
57 TQFrame *topFrame = plainPage();
58 TQVBoxLayout *topLayout =
new TQVBoxLayout( topFrame, 0, spacingHint() );
60 mCalendar =
new CalendarLocal( KOPrefs::instance()->mTimeZoneId );
61 mListView =
new KOListView( mCalendar, topFrame,
"PreviewDialog::ListView",
true );
62 topLayout->addWidget( mListView );
64 topLayout->setSpacing( spacingHint() );
65 topLayout->setMargin( marginHint() );
67 connect(
this, TQ_SIGNAL(user1Clicked()), TQ_SLOT(slotMerge()) );
68 connect(
this, TQ_SIGNAL(user2Clicked()), TQ_SLOT(slotAdd()) );
73 setButtonGuiItem( User2, KGuiItem( i18n(
"&Add as new calendar..."),
"add" ) );
75 setButtonGuiItem( User2, KGuiItem( i18n(
"&Add as new calendar"),
"add" ) );
81 PreviewDialog::~PreviewDialog()
83 if ( mLocalUrl && !mOriginalUrl.isLocalFile() ) {
84 TDEIO::NetAccess::removeTempFile( mLocalUrl->path() );
91 bool PreviewDialog::loadCalendar()
94 if ( !mOriginalUrl.isLocalFile() ) {
97 TDEIO::NetAccess::removeTempFile( mLocalUrl->path() );
102 if ( TDEIO::NetAccess::download( mOriginalUrl, tmpFile, 0 ) ) {
103 mLocalUrl =
new KURL( tmpFile );
108 mLocalUrl = &mOriginalUrl;
112 const bool success = mCalendar->load( mLocalUrl->path() );
114 if ( !success && !mOriginalUrl.isLocalFile() ) {
115 TDEIO::NetAccess::removeTempFile( mLocalUrl->path() );
117 mListView->showAll();
125 void PreviewDialog::slotMerge()
128 emit openURL( *mLocalUrl,
true );
129 emit dialogFinished(
this );
134 void PreviewDialog::slotAdd()
136 KURL finalUrl = mOriginalUrl;
137 if ( isTempFile() ) {
138 const TQString fileName =
139 KFileDialog::getSaveFileName( locateLocal(
"data",
"korganizer/" ),
140 i18n(
"*.vcs *.ics|Calendar Files" ),
141 this, i18n(
"Select path for new calendar" ) );
143 finalUrl = KURL( fileName );
145 if ( !TDEIO::NetAccess::copy( mOriginalUrl, finalUrl,
this ) && TDEIO::NetAccess::lastError() ) {
146 KMessageBox::error(
this, TDEIO::NetAccess::lastErrorString() );
151 if ( finalUrl.isValid() ) {
152 emit addResource( finalUrl );
153 emit dialogFinished(
this );
158 bool PreviewDialog::isTempFile()
const
160 return mOriginalUrl.path().startsWith( locateLocal(
"tmp",
"" ) );
163 #include "previewdialog.moc"
This class provides a multi-column list view of events.