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 mainLayout->addWidget( label, 1, 0 );
00070 mainLayout->addWidget( d->mURL, 1, 1 );
00071
00072 d->mFormatGroup = new QGroupBox( i18n( "Calendar Format" ), this );
00073
00074 d->mIcalButton = new QRadioButton( i18n( "iCalendar" ), d->mFormatGroup );
00075 d->mVcalButton = new QRadioButton( i18n( "vCalendar" ), d->mFormatGroup );
00076
00077 QVBoxLayout *vbox = new QVBoxLayout;
00078 vbox->addWidget( d->mIcalButton );
00079 vbox->addWidget( d->mVcalButton );
00080 vbox->addStretch( 1 );
00081 d->mFormatGroup->setLayout( vbox );
00082
00083 mainLayout->addWidget( d->mFormatGroup, 2, 1 );
00084 }
00085
00086 ResourceLocalConfig::~ResourceLocalConfig()
00087 {
00088 delete d;
00089 }
00090
00091 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
00092 {
00093 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00094 if ( res ) {
00095 d->mURL->setUrl( res->d->mURL.prettyUrl() );
00096 kDebug(5800) << "Format typeid().name():" << typeid( res->d->mFormat ).name();
00097 if ( typeid( *(res->d->mFormat) ) == typeid( ICalFormat ) ) {
00098 d->mIcalButton->setChecked(true);
00099 } else if ( typeid( *(res->d->mFormat) ) == typeid( VCalFormat ) ) {
00100 d->mVcalButton->setChecked(true);
00101 } else {
00102 kDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): Unknown format type";
00103 }
00104 } else {
00105 kDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed";
00106 }
00107 }
00108
00109 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
00110 {
00111 KUrl url = d->mURL->url();
00112
00113 if( url.isEmpty() ) {
00114 KStandardDirs dirs;
00115 QString saveFolder = dirs.saveLocation( "data", "korganizer" );
00116 QFile file( saveFolder + "/std.ics" );
00117
00118
00119 for ( int i = 0; file.exists(); ++i ) {
00120 file.setFileName( saveFolder + "/std" + QString::number(i) + ".ics" );
00121 }
00122
00123 KMessageBox::information(
00124 this,
00125 i18n( "You did not specify a URL for this resource. "
00126 "Therefore, the resource will be saved in %1. "
00127 "It is still possible to change this location "
00128 "by editing the resource properties.", file.fileName() ) );
00129
00130 url = KUrl::fromPath( file.fileName() );
00131 }
00132
00133 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00134 if ( res ) {
00135 res->d->mURL = url;
00136
00137 delete res->d->mFormat;
00138 if ( d->mIcalButton->isDown() ) {
00139 res->d->mFormat = new ICalFormat();
00140 } else {
00141 res->d->mFormat = new VCalFormat();
00142 }
00143 } else {
00144 kDebug(5800) << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed";
00145 }
00146 }