KCal Library
resourcelocalconfig.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "resourcelocalconfig.h"
00024 #include "resourcelocal.h"
00025 #include "resourcelocal_p.h"
00026 #include "vcalformat.h"
00027 #include "icalformat.h"
00028
00029 #include <klocale.h>
00030 #include <kmessagebox.h>
00031 #include <kdebug.h>
00032 #include <kstandarddirs.h>
00033
00034 #include <QtGui/QLabel>
00035 #include <QtGui/QGridLayout>
00036 #include <QtGui/QGroupBox>
00037
00038 #include <typeinfo>
00039
00040 #include "resourcelocalconfig.moc"
00041
00042 using namespace KCal;
00043
00048
00049 class KCal::ResourceLocalConfig::Private
00050 {
00051 public:
00052 Private()
00053 {}
00054 KUrlRequester *mURL;
00055 QGroupBox *mFormatGroup;
00056 QRadioButton *mIcalButton;
00057 QRadioButton *mVcalButton;
00058 };
00059
00060
00061 ResourceLocalConfig::ResourceLocalConfig( QWidget *parent )
00062 : KRES::ConfigWidget( parent ), d( new KCal::ResourceLocalConfig::Private )
00063 {
00064 resize( 245, 115 );
00065 QGridLayout *mainLayout = new QGridLayout( this );
00066
00067 QLabel *label = new QLabel( i18n( "Location:" ), this );
00068 d->mURL = new KUrlRequester( this );
00069 d->mURL->setFilter( i18n( "*.ics *.vcs|Calendar Files" ) );
00070 mainLayout->addWidget( label, 1, 0 );
00071 mainLayout->addWidget( d->mURL, 1, 1 );
00072
00073 d->mFormatGroup = new QGroupBox( i18n( "Calendar Format" ), this );
00074
00075 d->mIcalButton = new QRadioButton( i18n( "iCalendar" ), d->mFormatGroup );
00076 d->mVcalButton = new QRadioButton( i18n( "vCalendar" ), d->mFormatGroup );
00077
00078 QVBoxLayout *vbox = new QVBoxLayout;
00079 vbox->addWidget( d->mIcalButton );
00080 vbox->addWidget( d->mVcalButton );
00081 vbox->addStretch( 1 );
00082 d->mFormatGroup->setLayout( vbox );
00083
00084 mainLayout->addWidget( d->mFormatGroup, 2, 1 );
00085 }
00086
00087 ResourceLocalConfig::~ResourceLocalConfig()
00088 {
00089 delete d;
00090 }
00091
00092 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
00093 {
00094 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00095 if ( res ) {
00096 d->mURL->setUrl( res->d->mURL.prettyUrl() );
00097 kDebug() << "Format typeid().name():" << typeid( res->d->mFormat ).name();
00098 if ( typeid( *(res->d->mFormat) ) == typeid( ICalFormat ) ) {
00099 d->mIcalButton->setChecked(true);
00100 } else if ( typeid( *(res->d->mFormat) ) == typeid( VCalFormat ) ) {
00101 d->mVcalButton->setChecked(true);
00102 } else {
00103 kDebug() << "ERROR: Unknown format type";
00104 }
00105 } else {
00106 kDebug() << "ERROR: no ResourceLocal, cast failed";
00107 }
00108 }
00109
00110 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
00111 {
00112 KUrl url = d->mURL->url();
00113
00114 if( url.isEmpty() ) {
00115 KStandardDirs dirs;
00116 QString saveFolder = dirs.saveLocation( "data", "korganizer" );
00117 QFile file( saveFolder + "/std.ics" );
00118
00119
00120 for ( int i = 0; file.exists(); ++i ) {
00121 file.setFileName( saveFolder + "/std" + QString::number(i) + ".ics" );
00122 }
00123
00124 KMessageBox::information(
00125 this,
00126 i18n( "You did not specify a URL for this resource. "
00127 "Therefore, the resource will be saved in %1. "
00128 "It is still possible to change this location "
00129 "by editing the resource properties.", file.fileName() ) );
00130
00131 url = KUrl::fromPath( file.fileName() );
00132 }
00133
00134 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00135 if ( res ) {
00136 res->d->mURL = url;
00137
00138 delete res->d->mFormat;
00139 if ( d->mIcalButton->isDown() ) {
00140 res->d->mFormat = new ICalFormat();
00141 } else {
00142 res->d->mFormat = new VCalFormat();
00143 }
00144 } else {
00145 kDebug() << "ERROR: no ResourceLocal, cast failed";
00146 }
00147 }