libkcal
resourcelocalconfig.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <typeinfo>
00024
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027
00028 #include <klocale.h>
00029 #include <kmessagebox.h>
00030 #include <kdebug.h>
00031 #include <kstandarddirs.h>
00032
00033 #include "vcaldrag.h"
00034 #include "vcalformat.h"
00035 #include "icalformat.h"
00036
00037 #include "resourcelocal.h"
00038
00039 #include "resourcelocalconfig.h"
00040
00041 using namespace KCal;
00042
00043 ResourceLocalConfig::ResourceLocalConfig( QWidget* parent, const char* name )
00044 : KRES::ConfigWidget( parent, name )
00045 {
00046 resize( 245, 115 );
00047 QGridLayout *mainLayout = new QGridLayout( this, 2, 2 );
00048
00049 QLabel *label = new QLabel( i18n( "Location:" ), this );
00050 mURL = new KURLRequester( this );
00051 mainLayout->addWidget( label, 1, 0 );
00052 mainLayout->addWidget( mURL, 1, 1 );
00053
00054 formatGroup = new QButtonGroup( 1, Horizontal, i18n( "Calendar Format" ), this );
00055
00056
00057
00058 icalButton = new QRadioButton( i18n("iCalendar"), formatGroup );
00059 vcalButton = new QRadioButton( i18n("vCalendar"), formatGroup );
00060
00061 mainLayout->addWidget( formatGroup, 2, 1 );
00062 }
00063
00064 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
00065 {
00066 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00067 if ( res ) {
00068 mURL->setURL( res->mURL.prettyURL() );
00069 kdDebug(5800) << "Format typeid().name(): " << typeid( res->mFormat ).name() << endl;
00070 if ( typeid( *(res->mFormat) ) == typeid( ICalFormat ) )
00071 formatGroup->setButton( 0 );
00072 else if ( typeid( *(res->mFormat) ) == typeid( VCalFormat ) )
00073 formatGroup->setButton( 1 );
00074 else
00075 kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): Unknown format type" << endl;
00076 } else
00077 kdDebug(5700) << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed" << endl;
00078 }
00079
00080 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
00081 {
00082 QString url = mURL->url();
00083
00084 if( url.isEmpty() ) {
00085 KStandardDirs dirs;
00086 QString saveFolder = dirs.saveLocation( "data", "korganizer" );
00087 QFile file( saveFolder + "/std.ics" );
00088
00089
00090 for( int i = 0; file.exists(); ++i )
00091 file.setName( saveFolder + "/std" + QString::number(i) + ".ics" );
00092
00093 KMessageBox::information( this, i18n( "You did not specify a URL for this resource. Therefore, the resource will be saved in %1. It is still possible to change this location by editing the resource properties." ).arg( file.name() ) );
00094
00095 url = file.name();
00096 }
00097
00098 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00099 if (res) {
00100 res->mURL = url;
00101
00102 delete res->mFormat;
00103 if ( icalButton->isOn() ) {
00104 res->mFormat = new ICalFormat();
00105 } else {
00106 res->mFormat = new VCalFormat();
00107 }
00108 } else
00109 kdDebug(5700) << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed" << endl;
00110 }
00111
00112 #include "resourcelocalconfig.moc"
|