korganizer

previewdialog.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
00008     Author: Sergio Martins, <sergio.martins@kdab.com>    
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00023 
00024     As a special exception, permission is given to link this program
00025     with any edition of Qt, and distribute the resulting executable,
00026     without including the source code for Qt in the source distribution.
00027 */
00028 
00029 #include "previewdialog.h"
00030 
00031 #include "kolistview.h"
00032 #include "koprefs.h"
00033 #include "stdcalendar.h"
00034 
00035 #include <klocale.h>
00036 
00037 #include <libkcal/calendarlocal.h>
00038 
00039 #include <kstandarddirs.h>
00040 #include <kfiledialog.h>
00041 
00042 #include <qlabel.h>
00043 #include <qlayout.h>
00044 #include <qradiobutton.h>
00045 #include <qpushbutton.h>
00046 #include <qdialog.h>
00047 
00048 using namespace KCal;
00049 
00050 PreviewDialog::PreviewDialog( const KURL &url, QWidget *parent )
00051   : KDialogBase( Plain, i18n("Import Calendar/Event"), User1 | User2 | Cancel, User1, parent,
00052                  0, true, true, KGuiItem( i18n("&Merge into existing calendar"), "merge" ) ),
00053     mUrl( url )
00054 {
00055   QFrame *topFrame = plainPage();
00056   QVBoxLayout *topLayout = new QVBoxLayout( topFrame, 0, spacingHint() );
00057 
00058   mCalendar = new CalendarLocal( KOPrefs::instance()->mTimeZoneId );
00059   mCalendar->load( url.path() );
00060   mListView = new KOListView( mCalendar, topFrame, "PreviewDialog::ListView", true );
00061   topLayout->addWidget( mListView );
00062 
00063   mListView->showAll();
00064 
00065   topLayout->setSpacing( spacingHint() );
00066   topLayout->setMargin( marginHint() );
00067 
00068   connect( this, SIGNAL(user1Clicked()), SLOT(slotMerge()) );
00069   connect( this, SIGNAL(user2Clicked()), SLOT(slotAdd()) );
00070 
00071   // when someone edits a kmail attachment he's editing a tmp file, check for that
00072   // and if it's a tmp file then open a save dialog
00073   if ( isTempFile() ) {
00074     setButtonGuiItem( User2, KGuiItem( i18n("&Add as new calendar..."), "add" ) );
00075   } else {
00076     setButtonGuiItem( User2, KGuiItem( i18n("&Add as new calendar"), "add" ) );
00077   }
00078 }
00079 
00080 PreviewDialog::~PreviewDialog()
00081 {
00082   delete mCalendar;
00083 }
00084 
00085 void PreviewDialog::slotMerge()
00086 {
00087   emit openURL( mUrl, true );
00088   emit dialogFinished( this );
00089   accept();
00090 }
00091 
00092 void PreviewDialog::slotAdd()
00093 {
00094   KURL finalUrl = mUrl;
00095   if ( isTempFile() ) {
00096     const QString fileName = KFileDialog::getSaveFileName( mUrl.fileName(), QString::null,
00097                                                            0, i18n( "Select path for new calendar" ) );
00098     finalUrl = KURL( fileName );
00099   }
00100 
00101   if ( finalUrl.isValid() ) {
00102     emit addResource( finalUrl );
00103     emit dialogFinished( this );
00104     accept();
00105   }
00106 }
00107 
00108 bool PreviewDialog::isTempFile() const
00109 {
00110   return mUrl.path().startsWith( locateLocal( "tmp", "" ) );
00111 }
00112 
00113 #include "previewdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys