summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2005-03-30 13:24:56 (UTC)
committer zautrix <zautrix>2005-03-30 13:24:56 (UTC)
commit056f171723a9301aea5a65340dffeda34e078abf (patch) (unidiff)
tree7930525c801dd9c5d9a910b71bca7dc79e10f666 /kabc
parentb5222dd7a607f78235b1ea39fea0f95a9c08ccd3 (diff)
downloadkdepimpi-056f171723a9301aea5a65340dffeda34e078abf.zip
kdepimpi-056f171723a9301aea5a65340dffeda34e078abf.tar.gz
kdepimpi-056f171723a9301aea5a65340dffeda34e078abf.tar.bz2
fixes
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefile.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 4ab7f02..0e6c2a3 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -81,106 +81,112 @@ ResourceFile::ResourceFile( const KConfig *config )
81 default_fileName = StdAddressBook::fileName(); 81 default_fileName = StdAddressBook::fileName();
82 82
83 KConfig *cfg = (KConfig *)config; 83 KConfig *cfg = (KConfig *)config;
84 if ( cfg ) { 84 if ( cfg ) {
85 fileName = cfg->readEntry( "FileName", default_fileName ); 85 fileName = cfg->readEntry( "FileName", default_fileName );
86 formatName = cfg->readEntry( "FileFormat", "vcard" ); 86 formatName = cfg->readEntry( "FileFormat", "vcard" );
87 } else { 87 } else {
88 fileName = default_fileName; 88 fileName = default_fileName;
89 formatName = "vcard"; 89 formatName = "vcard";
90 } 90 }
91 91
92 init( fileName, formatName ); 92 init( fileName, formatName );
93} 93}
94 94
95ResourceFile::ResourceFile( const QString &fileName , 95ResourceFile::ResourceFile( const QString &fileName ,
96 const QString &formatName ) 96 const QString &formatName )
97 : Resource( 0 ) 97 : Resource( 0 )
98{ 98{
99// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 99// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
100 100
101 101
102 102
103 init( fileName, formatName ); 103 init( fileName, formatName );
104} 104}
105 105
106void ResourceFile::init( const QString &fileName, const QString &formatName ) 106void ResourceFile::init( const QString &fileName, const QString &formatName )
107{ 107{
108 mFormatName = formatName; 108 mFormatName = formatName;
109 109
110 FormatFactory *factory = FormatFactory::self(); 110 FormatFactory *factory = FormatFactory::self();
111 mFormat = factory->format( mFormatName ); 111 mFormat = factory->format( mFormatName );
112 112
113 if ( !mFormat ) { 113 if ( !mFormat ) {
114 mFormatName = "vcard"; 114 mFormatName = "vcard";
115 mFormat = factory->format( mFormatName ); 115 mFormat = factory->format( mFormatName );
116 } 116 }
117 117
118#ifndef NO_DIRWATCH 118#ifndef NO_DIRWATCH
119 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 119 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
120 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 120 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
121 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 121 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
122#endif 122#endif
123 123
124 124
125 QString localKdeDir; 125 QString localKdeDir;
126 localKdeDir = readEnvPath("LOCALMICROKDEHOME"); 126 localKdeDir = readEnvPath("LOCALMICROKDEHOME");
127 if ( ! localKdeDir.isEmpty() ) { 127 if ( ! localKdeDir.isEmpty() ) {
128 qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() ); 128 qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() );
129 129 QFileInfo fi ( fileName );
130 130 QString localname = localKdeDir + "/apps/kabc/" + fi.fileName ();
131 131 QFileInfo fi2 ( localname );
132 if ( ! fi2.exists() ) {
133 KMessageBox::error(0,i18n("Addressbook resource file not found:\n '%1'.\nIn LOCAL mode only resource files in\n'%2'\nare supported.\n(i.e. in the dir ./apps/kabc/ relative to the kapi(.exe) binary.)\n\nIf you are starting KA/Pi for the very first time\nyou will get this error message as well.\nIt will create the missing file automatically for you.").arg(localname).arg(localKdeDir+"/apps/kabc/") );
134 setFileName( localname );
135 return;
136
137 } else {
138 qDebug("Local resource file found. Changing filename to: %s",localname.latin1() );
139 setFileName( localname );
140 return;
141 }
132 142
133 } 143 }
134 qDebug("RESOURCE: %s ", fileName.latin1()); 144 setFileName( fileName );
135
136
137
138 setFileName( fileName );
139} 145}
140 146
141ResourceFile::~ResourceFile() 147ResourceFile::~ResourceFile()
142{ 148{
143 delete mFormat; 149 delete mFormat;
144 mFormat = 0; 150 mFormat = 0;
145} 151}
146 152
147void ResourceFile::writeConfig( KConfig *config ) 153void ResourceFile::writeConfig( KConfig *config )
148{ 154{
149 155
150 config->setGroup( "Resource_" + identifier() ); 156 config->setGroup( "Resource_" + identifier() );
151 Resource::writeConfig( config ); 157 Resource::writeConfig( config );
152 158
153 config->writeEntry( "FileName", fileName() ); 159 config->writeEntry( "FileName", fileName() );
154 config->writeEntry( "FileFormat", mFormatName ); 160 config->writeEntry( "FileFormat", mFormatName );
155 161
156// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 162// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
157 163
158} 164}
159 165
160Ticket *ResourceFile::requestSaveTicket() 166Ticket *ResourceFile::requestSaveTicket()
161{ 167{
162 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 168 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
163 169
164 if ( !addressBook() ) return 0; 170 if ( !addressBook() ) return 0;
165 171
166#ifdef ALLOW_LOCKING 172#ifdef ALLOW_LOCKING
167 if ( !lock( mFileName ) ) { 173 if ( !lock( mFileName ) ) {
168 qDebug("unablt to lock file "); 174 qDebug("unablt to lock file ");
169 return 0; 175 return 0;
170 } 176 }
171#endif 177#endif
172 return createTicket( this ); 178 return createTicket( this );
173} 179}
174 180
175 181
176bool ResourceFile::doOpen() 182bool ResourceFile::doOpen()
177{ 183{
178 QFile file( fileName() ); 184 QFile file( fileName() );
179 qDebug("ResourceFile::openfile %s ", fileName().latin1()); 185 qDebug("ResourceFile::openfile %s ", fileName().latin1());
180 186
181 if ( !file.exists() ) { 187 if ( !file.exists() ) {
182 // try to create the file 188 // try to create the file
183 bool ok = file.open( IO_WriteOnly ); 189 bool ok = file.open( IO_WriteOnly );
184 if ( ok ) 190 if ( ok )
185 file.close(); 191 file.close();
186 192