Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'AddressBook (./kdelibs/kab/addressbook.h:169)
class AddressBook : public QFrame
{
// ############################################################################
Q_OBJECT
// ----------------------------------------------------------------------------
public:
/** The return values of some AddressBook member functions are #ErrorCode
* values. */
enum ErrorCode {
NoError, /**< No error, the operation did not fail. */
PermDenied, /**< Access permissions for the operation are not available. */
Locked, /**< An writing operation on a locked file was requested. */
Rejected, /**< The requested operation has been rejected by the user. */
NoSuchEntry, /**< An entry has been referenced using a unknown key. */
NoEntry, /**< You tried to retrieve an entry but there is none. */
NoFile, /**< No file has been loaded by now. */
NoSuchFile, /**< A filename could not be found on the filesystem. */
InternError, /**< A error in kab's internal logic occured. */
OutOfRange, /**< An index value was out of the allowed range. */
NotImplemented /**< The requested operation is not implemented. */
};
/** Some predefined telephone types. More are possible, but these are
* provided and thus, for example, translated. */
enum Telephone {
NoTelephone,
Fixed,
Mobile,
Fax,
Modem,
User1,
User2,
User3
};
/** Each entry in a loaded database has its own ::Entry object.
*
* \par The structure of the address database
* As you might have read, kab uses the QConfigDB class to manage its
* data files. This class is intended to handle hierarchical structures.
* Thus, kab is able to create human readable but still deep and complex
* data files. This paragraph describes the overall structure of the
* files, the next two deal with special parts of it. <BR>
* First of all, kab II data files (that usually end with \c .kab, while in
* kab 1 the fixed file name was \c addressbook.database) have two main
* sections (see the documentation of the QConfigDB and Section classes),
* one is called \c config, it contains different file specific
* configuration settings like the last displayed entry, and one section
* called \c entries that in turn contains a subsection for each entry in
* the database file. The keys of this subsections are the literal strings
* that are used in the KabKey class in the member KabKey::key. Each entry
* subsection has some key-value-pairs described below and another
* subsection "addresses" with one or more addresses in it. See the
* following example for a kab II data file (without any key-value-pairs):
* <BR> <PRE>
* [config]
* [END]
* [entries]
* [1] (the first entry with literal key "1")
* [addresses]
* [1] (the first address, addresses are enumerated)
* [END]
* [2] (the second address)
* [END]
* ... (more addresses may follow)
* [END]
* [END]
* [2] (the second entry)
* [addresses]
* [1]
* [END]
* [END]
* [END]
* ... (more entries may follow)
* [END] </PRE> <BR>
*
* \par The fields an entry contains
* An entry contains all settings that are expected to be unique for all
* addresses directly as key-value-pairs. Everything that is part of a
* specific address of this person is part of an object of the member list
* \c addresses referenced in the next paragraph. <BR>
* The keys defined directly in the entry sections are: <DL>
* <DD> "title" The title of that person. </DD>
* <DD> "rank" A possible military rank of that person. </DD>
* <DD> "fn" The formatted name. If it is not empty, it replaces the
* standard combination of the other name fields in the address
* display. </DD>
* <DD> "nameprefix" A possible name prefix. </DD>
* <DD> "firstname" The first name. </DD>
* <DD> "middlename" The middle name. </DD>
* <DD> "lastname" The last name. </DD>
* <DD> "birthday" The birthday (a QDate). </DD>
* <DD> "comment" A free form comment. </DD>
* <DD> "talk" The talk addresses (a string list). </DD>
* <DD> "emails" The email addresses (a string list). </DD>
* <DD> "keywords" A list of free-form keywords. </DD>
* <DD> "telephone" A list of telephone numbers in a special format. </DD>
* <DD> "URLs" A list of internet addresses. </DD>
* <DD> "user_1" The first user-declared data field. </DD>
* <DD> "user_2" The second user-declared data field. </DD>
* <DD> "user_3" The third user-declared data field. </DD>
* <DD> "user_4" The fourth user-declared data field. </DD>
* </DL>
* See the next section for a description of the addresses subsections.
*
* \par The fields of the addresses subsections
* The section for each entry contains a subsection \c addresses with
* in turn a subsection for each address. The addresses are enumerated
* in the order they are inserted, their keys are the numbers of
* inserting converted to a string. <BR>
* The keys defined in an address subsection are: <DL>
* <DD> "headline" A headline shown for the address. </DD>
* <DD> "position" The position of the person. </DD>
* <DD> "org" The organisation. </DD>
* <DD> "orgunit" The organisational unit. </DD>
* <DD> "orgsubunit" The organisational subunit. </DD>
* <DD> "role" The role of the person. </DD>
* <DD> "deliverylabel" A label for delivering to this address. </DD>
* <DD> "address" The street, house no., flat etc line. </DD>
* <DD> "zip" A zip or postal code. </DD>
* <DD> "town" The town the person lives in in this address. </DD>
* <DD> "country" The country for federal states. </DD>
* <DD> "state" The state for federal states. </DD>
*
* \par The local configuration section
* For each kab II database file there are some settings that apply
* only to the file itselfes, not to all kab databases the user works
* with. These settings are called the local configuration. The settings
* are stored in the \c config section of the local file. The following
* keys are declared in this section: <DL>
* <DD> "user_1" The \e name of the first user-declared field. </DD>
* <DD> "user_2" The \e name of the second user-declared field. </DD>
* <DD> "user_3" The \e name of the third user-declared field. </DD>
* <DD> "user_4" The \e name of the fourth user-declared field. </DD>
* </DL>
* More fields will surely follow.
**/
class Entry {
protected:
/** \internal The pointer to the file the entry is read from. */
// const QConfigDB *file;
public:
// types:
/** Since an entry may have different addresses, we need a type for them.
* Multiple addresses are used to distinguish between addresses at home
* and work, for example. */
struct Address {
QString headline; /**< The headline for this address. */
QString position; /**< The position of the person at this address. */
QString org; /**< The organisation of the person at this address. */
QString orgUnit; /**< The org unit of the person at this address. */
QString orgSubUnit; /**< The org subunit of the person at this address. */
QString deliveryLabel; /**< The description for delivering. */
QString address; /**< Street, with house number. */
QString zip; /**< Zip or postal code. */
QString town; /**< The town. */
QString country; /**< The country for federal states. */
QString state; /**< The state for federal states. */
};
/** Contains one or more Address objects. */
std::list<AddressBook::Entry::Address> addresses;
// methods:
/** Use this method to retrieve the address at the given \a index.
* The method is provided for convenience. The address data is
* returned in \a address. */
AddressBook::ErrorCode getAddress(int index, Address& address);
/** Returns the number of addresses of this entry. */
int noOfAddresses() const;
// members:
// this parts are assumed to be unique for every entry:
QString title; /**< The title of the person. */
QString rank; /**< The rank of the person. */
QString fn; /**< The formatted name of the person. */
QString nameprefix; /**< A possibly name prefix for that person. */
QString firstname; /**< The first name of the person. */
QString middlename; /**< The middle name of the person. */
QString lastname; /**< The last name of the person. */
QDate birthday; /**< The birthday of this person. */
QString comment; /**< The comment. */
QStringList talk; /**< The talk addresses. */
QStringList emails; /**< The email addresses. */
QStringList keywords; /**< The user defined keywords for searching. */
/** Telephon numbers and types. This list contains combinations of telephone
* numbers and the types of the phones, in this order. See enum
* Telephone above. */
QStringList telephone;
QStringList URLs; /**< The home or related web pages of this person. */
QString user1; /**< The first user-declared field. */
QString user2; /**< The second user-declared field. */
QString user3; /**< The third user-declared field. */
QString user4; /**< The fourth user-declared field. */
};
/** The constructor. If \e load is true, the user standard file will
* automatically be loaded into the object. */
AddressBook(QWidget* parent=0, const char* name=0, bool load=true);
~AddressBook(); /**< The destructor. */
/** Get the internal state of the object.
* If no problem occured, it returns ::NoError.
* If the standard or the latest opened file could not be loaded,
* it returns ::PermDenied.*/
ErrorCode getState();
/** Load the file with the given path. An empty file name reloads the
* currently opened file. */
ErrorCode load(QString filename="");
/** Save the file to the given path and file name. An empty file name saves
* to the file where the database has been read from.
* If force is true, the method will switch to r/w mode for saving and
* back. */
ErrorCode save(const QString& filename="", bool force=false);
/** Close this file.
* ::closeFile assures sure that the ::data object is reset no matter of the
* state of the assigned file.
* If \a save is true, it will not close the file if it could not be
* saved. */
ErrorCode closeFile(bool saveit=true);
/** Retrieve an entry from the database by its key. */
ErrorCode getEntry(const KabKey& key, Entry&);
/** Retrieve the Section of the entry directly, returning a section object. */
ErrorCode getEntry(const KabKey& key, Section*&);
/** Get all entries in displaying order. This method might be slow (O(n)). */
ErrorCode getEntries(std::list<Entry>&);
/** Add an ::Entry, \a return the new key for further operations.
* If update is false, the mirror map will not be affected, if it is true,
* the mirror map gets updated, too. */
ErrorCode add(const Entry&, KabKey& key, bool update=true);
/** Set the entry with the given key to the new contents. Be aware of
* #PermDenied for read-only databases or file sharing conflicts. You cannot
* change entries in a database for which you do not have write access. */
ErrorCode change(const KabKey& key, const Entry&);
/** Remove the entry with the given key. Returns #NoSuchEntry if there is no
* entry with this key, #PermDenied for read only databases. */
ErrorCode remove(const KabKey& key);
/** Returns the number of entries in the loaded database. */
unsigned int noOfEntries();
/** This method returns the literal name for the entry,
* containing either the formatted name (if given) or a
* combination of the first, additional and last name.
* The name is returned in \a text.
* If \a reverse is false, the text looks like
* firstname (add. name) last name,
* if it is true,
+ last name, first name (add. name).
* If \a initials is true, the text contains initials only:
* f. a. name [with reverse==false] or
* name, f. a. [with reverse==true].
* If there is no entry with this key, the method returns ::NoSuchEntry.
*/
ErrorCode literalName(const KabKey& key, QString& text,
bool reverse=false, bool initials=false);
/** This is an overloaded method that differs only in the arguments it takes.
*/
ErrorCode literalName(const Entry& entry, QString& text,
bool reverse=false, bool initials=false);
/** Get the key of the item in the selector with the given index. */
ErrorCode getKey(int index, KabKey&);
/** Get the index of this key in the selector. This is the reverse
functionality to getKey(). */
ErrorCode getIndex(const KabKey&, int&);
/** Fill the string list with name lines. If your application shows a combobox
* containing an overview over the currently loaded KabAPI database, then
* call this method when receiving the signal ::changed and display the list
* in the combo. */
ErrorCode getListOfNames(QStringList*, bool reverse=true, bool initials=true);
/** Hand over the configuration database. Careful! */
QConfigDB* getConfig();
/** This method returns the QConfigDB section where the configuration of the
currently opened file is stored. It might be used to retrieve or to modify
these settings. The file-specific settings are saved along with
the open file.
Do not confuse the configuration section of the opened file with
the configuration of the program. Each file might have its own
local configuration for some settings where it makes sense.
@ return Null if no file has been opened.
*/
Section *configurationSection();
/** This method opens a dialog for configuring the file-specific settings
* for the loaded file. The database is automatically saved if the user
* accepts the changes. */
// ErrorCode configureFile();
/** Creates a new database with the given file name. If the filename is
* empty, it creates the users standard data file. The method does not load
* the new database. */
ErrorCode createNew(const QString& filename="");
/** Creates the local configuration file. The filename is fixed to
* \c kab.config, it will be created in the local kab directory
* (\c $HOME/.kde/share/apps/kab). Adapt the global configuration template
* file (\c $KDEDIR/share/apps/kab/template.config) for unusual site-specific
* settings.
* The method does not load the new config file. */
ErrorCode createConfigFile();
ErrorCode loadConfigFile(); /**< Load the local configuration file. */
// ErrorCode configureKab(); /**< Open the configuration dialog for the KabAPI. */
// QSize sizeHint(); /**< The preferred (minimal) size of the view. */ // ni
/** This method parses a vCard and creates an Entry object from it. */
ErrorCode makeEntryFromVCard(const QString& card, Entry&);
/** This method creates a vCard string from an entry. */
ErrorCode makeVCardFromEntry(const Entry& entry, QString card);
/** Returns the complete path to the user standard file. An empty path
* indicates an error, but this should not happen. It is NOT ensured
* that the file exists. */
QString getStandardFilename();
/** Call this to get a telephone type translated to the locale. */
static QString phoneType(AddressBook::Telephone);
// ----------------------------------------------------------------------------
protected:
QConfigDB *config; /**< The configuration database. */
QConfigDB *data; /**< The currently open data files. */
StringKabKeyMap *entries; /**< The mirror map. */
ErrorCode state; /**< The internal state of the object. */
/** Get the next available entry key for this file. For internal use only. */
KabKey nextAvailEntryKey();
/** Returns true if both pathes point to the same file.
* The method resolves relative file names to find this out. */
bool isSameFile(const QString& a, const QString& b);
/** Parse the section and copy its contents into \a entry.
* The method expects a subsection called \e addresses that contains a
* number of subsections each containing data for one Entry::Address object.
* All other fields are copied directly into the members of \a entry. */
ErrorCode makeEntryFromSection(Section*, Entry&); // nicht beendet
/** For internal use only. This parses one address subsection and puts its
* contents in the Address object. */
ErrorCode makeAddressFromMap(KeyValueMap*, Entry::Address&);
/** Create a section from the entries settings. */
ErrorCode makeSectionFromEntry(const Entry&, Section&); // nicht beendet
/** Update the mirror map after changes of the database. */
ErrorCode updateMirrorMap();
/** Get the entry section of the file. Maybe a NULL pointer if no file is
* opened. */
Section* entrySection();
/** Lock the file for changing.
* Since all database files are opened read-only, they must be locked before
* the files contents are changed. After changing the file must be saved and
* unlocked. Returns ::PermDenied if the file could not be locked, ::NoError
* if it was not locked and is now, and ::Locked if the file is already
* locked.
* @see unlock
* @see QConfigDB::setFileName */
ErrorCode lock();
/** Unlock the file after changes. Returns ::NoError if the file was locked
* and could be unlocked, ::PermDenied if the file was not locked and
* possibly ::InternError if anything fails.
* @see ::lock
* @see QConfigDB::setFileName */
ErrorCode unlock();
/** Set the background image. Kab will store a deep copy of the image.
* If the image is a null image nothing will be displayed. */
// void setBackground(const QImage&);
/** Enable or disable the background image. */
// void setBackgroundEnabled(bool state);
/** Retrieve wether the background image is enabled or not. */
// bool getBackgroundEnabled();
/** Set if the URL labels are interactive. */
// void setInteractiveMode(bool state);
/** Get if the URL labels are interactive. */
// bool getInteractiveMode();
/** Returns the users own kab data directory. Usually ~/.kde/share/apps/kab. */
QString baseDir();
/** Returns the global data dir of kab (usually $KDEDIR/share/apps/kab). */
// QString globalDir(); // replaced by locate, hopefully
// ----------------------------------------------------------------------------
protected slots:
/** Called when ::data has been cleared or reloaded. */
void reloaded(QConfigDB*);
/** Called when the \e file assigned to ::data has changed on disk. */
void dataFileChanged();
/** Called when the \e file assigned to ::config has changed on disk. */
void configFileChanged();
// ----------------------------------------------------------------------------
public slots:
/** This slot is called when an external object changed the database through
the kabapi. */
void externalChange();
// ----------------------------------------------------------------------------
signals:
void changed(); /**< The entries have changed, update the selector. */
void setStatus(const QString&); /**< This is kab radio with the news... */
void newFile(const QString&); /**< Notifies changes of the file name. */
// ############################################################################
private:
class AddressBookPrivate;
AddressBookPrivate *d;
};
kdelibs'AddressBook::AddressBook() (./kdelibs/kab/addressbook.cc:154)
AddressBook::AddressBook(QWidget* parent, const char* name, bool loadit)
: QFrame(parent, name),
config(new QConfigDB(this)),
data(new QConfigDB(this)),
entries(new StringKabKeyMap),
state(NoFile)
{
register bool GUARD; GUARD=true;
// ###########################################################################
QString dir, filename;
// ----- do memory checks (do not rely on exception handling):
if(config==0 || data==0 || entries==0)
{
KMessageBox::error(this,
i18n("Cannot initialize local variables."),
i18n("Out of memory"));
kapp->quit(); // It is critical, but will possibly never happen.
}
connect(data, SIGNAL(fileChanged()), SLOT(dataFileChanged()));
connect(data, SIGNAL(changed(QConfigDB*)),
SLOT(reloaded(QConfigDB*)));
connect(config, SIGNAL(fileChanged()), SLOT(configFileChanged()));
// ----- set style:
dir=baseDir();
// ----- open or create the configuration file and load it:
filename=dir+"/"+STD_CONFIGFILENAME;
if(::access(filename.ascii(), F_OK)!=0) // if it does not exist
{
if(createConfigFile()!=NoError)
{
KMessageBox::error(this,
i18n("Your local kab configuration file\n"
"\"%1\"\n"
"could not be created. kab will probably not\n"
"work correctly without it.\n"
"Make sure you did not remove writing permission\n"
"from your local kde directory.").arg(filename),
i18n("File error"));
state=PermDenied;
} else {
KMessageBox::information
(this,
i18n("kab has created your local configuration file in\n"
"\"%1\"").arg(filename));
}
}
loadConfigFile();
// ----- check and possibly create user standard file:
filename=dir+"/"+STD_USERFILENAME;
if(::access(filename.ascii(), F_OK)!=0) // if it does not exist
{
if(createNew(filename)!=NoError) // ...and we cannot create it
{
KMessageBox::error(this,
i18n("Your standard kab database file\n"
"\"%1\"\n"
"could not be created. kab will probably not\n"
"work correctly without it.\n"
"Make sure you did not remove writing permission\n"
"from your local kde directory.").arg(filename),
i18n("File error"));
state=PermDenied;
} else {
KMessageBox::information
(this,
i18n("kab has created your standard addressbook in\n\"%1\"")
.arg(filename));
}
}
// ----- load the user standard file:
if(loadit)
{
if(load(filename)!=NoError)
{ // ----- the standard file could not be loaded
state=PermDenied;
} else {
// ----- create the backup file:
QString temp=data->fileName();
if(data->setFileName(temp+".backup", false, false))
{
if(!data->save())
{
KMessageBox::information(this,
i18n("Cannot create backup file (permission denied)."),
i18n("File error"));
}
} else {
KMessageBox::error(this,
i18n("Cannot open backup file for "
"writing (permission denied)."),
i18n("File error"));
}
// ----- reset the filename:
if(!data->setFileName(temp, true, true))
{
KMessageBox::error(this,
i18n("Critical error:\n"
"Permissions changed in local directory!"),
i18n("File error"));
closeFile(false);
state=PermDenied;
} else {
state=NoError;
}
}
}
// -----
data->watch(true);
// ###########################################################################
}
kdelibs'AddressBook::~AddressBook() (./kdelibs/kab/addressbook.cc:267)
AddressBook::~AddressBook()
{
// ###########################################################################
delete data;
delete config;
delete entries;
// ###########################################################################
}
kdelibs'AddressBook::getConfig() (./kdelibs/kab/addressbook.cc:276)
QConfigDB* AddressBook::getConfig()
{
// ###########################################################################
return config;
// ###########################################################################
}
AddressBook::ErrorCode AddressBook::getState()
{
// ###########################################################################
return state;
// ###########################################################################
}
AddressBook::ErrorCode AddressBook::load(QString filename)
{
// ----- Remark: Close the file if it could not be loaded!
// ###########################################################################
const QString dir=baseDir();
ErrorCode rc=NoError;
QFileInfo newfile, oldfile;
// -----
if(filename.isEmpty())
{ // ----- reload the curent data file:
filename=data->fileName();
}
if(filename.isEmpty()) // there was never a filename set:
{
state=NoFile;
return NoFile;
}
// -----
newfile.setFile(filename);
oldfile.setFile(data->fileName());
if(isSameFile(filename, data->fileName()))
{ // ----- possibly deleted file:
if(data->load())
{
emit(setStatus(i18n("File reloaded.")));
state=NoError;
} else {
switch
(QMessageBox::information
(this, i18n("File error"),
i18n("The currently loaded file\n\"")
+oldfile.absFilePath()+"\"\n"+
i18n
("cannot be reloaded. kab may close or save it.\n"
"Save it if you accidently deleted your data file.\n"
"Close it if you intended to do so.\n"
"Your file will be closed by default."),
i18n("&Close"), i18n("&Save")))
{
case 1: // save
if(!data->save(i18n("(Safety copy on file error)"), true))
{
KMessageBox::information(this,
i18n("Cannot save the file, will close it now."),
i18n("File error"));
closeFile(false);
rc=PermDenied;
}
break; // no error if we could save the file
default: // close
closeFile(false);
rc=NoSuchFile;
break;
}
}
} else { // ----- set new filename
if(data->setFileName(filename, true, true))
{
if(data->load())
{
emit(changed());
emit(setStatus(i18n("File opened.")));
state=NoError;
} else {
KMessageBox::information(this,
i18n("Could not load the file."),
i18n("File error"));
closeFile(false);
emit(setStatus(i18n("No such file.")));
rc=NoSuchFile;
}
} else {
if(QMessageBox::information
(this, i18n("No such file"),
i18n("The file\n\"")
+filename+"\"\n"+
i18n(" cannot be found. Create a new one?"),
i18n("OK"), i18n("Cancel"))==0)
{
if(createNew(filename)==NoError)
{
emit(setStatus(i18n("New file.")));
} else { // ----- do not close here, stick with the old file:
emit(setStatus(i18n("Cancelled.")));
}
}
}
}
// -----
if(rc==NoError)
{
updateMirrorMap();
}
// -----
return rc;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::getListOfNames(QStringList* strings, bool reverse, bool initials)
{
register bool GUARD; GUARD=false;
// ###########################################################################
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::getListOfNames: called.\n";
StringKabKeyMap::iterator pos;
QString desc;
ErrorCode rc=NoError;
ErrorCode temp;
// ----- erase the list contents:
strings->clear();
// ----- ...and fill it:
for(pos=entries->begin(); pos!=entries->end(); ++pos)
{
temp=literalName((*pos).second, desc, reverse, initials);
if(temp!=AddressBook::NoError)
{
desc=i18n("(Internal error in kab)");
rc=InternError;
}
if(desc.isEmpty())
{
desc=i18n("(empty entry)");
}
kdDebug(GUARD, KAB_KDEBUG_AREA) <<
"AddressBook::getListOfNames: adding " << desc << endl;
strings->append(desc);
}
// ----- any problems?
kdDebug(GUARD, KAB_KDEBUG_AREA)
<< "AddressBook::getListOfNames: done, "
<< strings->count()
<< " entries.\n";
return rc;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::literalName(const KabKey& key, QString& text, bool rev, bool init)
{
// ###########################################################################
Entry entry;
ErrorCode rc;
// ----- get the entry:
rc=getEntry(key, entry);
if(rc!=NoError)
{
return rc;
}
// -----
return literalName(entry, text, rev, init);
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::literalName(const Entry& entry, QString& text, bool rev, bool init)
{
register bool GUARD; GUARD=false;
// ###########################################################################
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::literalName: called.\n";
QString firstname, middlename, lastname, nameprefix;
// ----- is the formatted name set?
if(!entry.fn.isEmpty())
{
text=entry.fn;
kdDebug(GUARD, KAB_KDEBUG_AREA) <<
"AddressBook::literalName: done (fn).\n";
return NoError;
}
// ----- prepare the strings:
firstname=entry.firstname.simplifyWhiteSpace();
middlename=entry.middlename.simplifyWhiteSpace();
lastname=entry.lastname.simplifyWhiteSpace();
nameprefix=entry.nameprefix.simplifyWhiteSpace();
// ----- create the initials:
if(init)
{
if(!firstname.isEmpty()) firstname=firstname.mid(0, 1)+'.';
if(!middlename.isEmpty()) middlename=middlename.mid(0, 1)+'.';
// if(!lastname.isEmpty()) lastname=lastname.mid(0, 1)+'.';
}
// ----- assemble the string:
text="";
if(rev)
{ // name, firstname - add. name - name prefix
if(!lastname.isEmpty())
{
text=lastname;
}
if(!firstname.isEmpty() || !middlename.isEmpty() || !nameprefix.isEmpty())
{
text+=',';
}
if(!firstname.isEmpty())
{
if(!text.isEmpty())
{
text+=' ';
}
text+=firstname;
}
if(!middlename.isEmpty())
{
if(!text.isEmpty())
{
text+=' ';
}
text+=middlename;
}
if(!nameprefix.isEmpty())
{
if(!text.isEmpty())
{
text+=' ';
}
text+=nameprefix;
}
} else {
// firstname - add. name - name prefix - name
text=firstname;
if(!middlename.isEmpty())
{
if(!text.isEmpty())
{
text+=' ';
}
text+=middlename;
}
if(!nameprefix.isEmpty())
{
if(!text.isEmpty())
{
text+=' ';
}
text+=nameprefix;
}
if(!lastname.isEmpty())
{
if(!text.isEmpty())
{
text+=' ';
}
text+=lastname;
}
}
// -----
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::literalName: done: "
<< text << ".\n";
return NoError;
// ###########################################################################
}
unsigned int
kdelibs'AddressBook::noOfEntries() (./kdelibs/kab/addressbook.cc:542)
AddressBook::noOfEntries()
{
// ###########################################################################
return entries->size();
// ###########################################################################
}
void
kdelibs'AddressBook::dataFileChanged() (./kdelibs/kab/addressbook.cc:550)
AddressBook::dataFileChanged()
{
// ###########################################################################
load();
// ###########################################################################
}
void
kdelibs'AddressBook::configFileChanged() (./kdelibs/kab/addressbook.cc:558)
AddressBook::configFileChanged()
{
register bool GUARD; GUARD=true;
// ###########################################################################
if(!config->load())
{
KMessageBox::error(this,
i18n("Cannot reload configuration file!"),
i18n("File error"));
} else {
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::configFileChanged: "
"config file reloaded.\n";
emit(setStatus(i18n("Configuration file reloaded.")));
}
// ###########################################################################
}
void
kdelibs'AddressBook::reloaded() (./kdelibs/kab/addressbook.cc:576)
AddressBook::reloaded(QConfigDB* db)
{
register bool GUARD; GUARD=true;
// ###########################################################################
if(db==data)
{
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::reloaded: file has been "
"reloaded.\n";
updateMirrorMap(); // WORK_TO_DO: what's up with the return value?
changed();
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::save(const QString& filename, bool force)
{
// ###########################################################################
if(filename.isEmpty())
{
if(data->save(0, force))
{
emit(setStatus(i18n("File saved.")));
return NoError;
} else {
return PermDenied;
}
} else {
if(data->setFileName(filename, false, false))
{
if(data->save(0, true))
{
emit(newFile(filename));
return NoError;
} else {
return PermDenied;
}
} else {
return PermDenied;
}
}
// ###########################################################################
}
bool
kdelibs'AddressBook::isSameFile() (./kdelibs/kab/addressbook.cc:621)
AddressBook::isSameFile(const QString& a, const QString& b)
{
// ###########################################################################
QFileInfo filea(a), fileb(b);
// -----
return filea.absFilePath()==fileb.absFilePath();
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::closeFile(bool saveit)
{
// ###########################################################################
if(saveit)
{
if(save()!=NoError)
{
emit(setStatus(i18n("Permission denied.")));
return PermDenied;
}
}
data->clear();
// data->reset(); WORK_TO_DO: File name is not reset by now.
emit(setStatus(i18n("File closed.")));
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::getEntry(const KabKey& key, Entry& entry)
{
// ###########################################################################
Section *section;
// -----
if(getEntry(key, section)==NoError)
{
return makeEntryFromSection(section, entry);
} else {
return NoSuchEntry;
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::getEntry(const KabKey& key, Section*& section)
{
register bool GUARD; GUARD=false;
// ###########################################################################
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::getEntry: searching entry "
"with key " << key.getKey().data() << endl;
StringKabKeyMap::iterator pos;
// -----
for(pos=entries->begin(); pos!=entries->end(); ++pos)
{
if((*pos).second==key)
{
kdDebug(GUARD, KAB_KDEBUG_AREA) <<
"AddressBook::getEntry: key exists." << endl;
break;
}
}
if(pos==entries->end())
{
kdDebug(GUARD, KAB_KDEBUG_AREA) <<
"AddressBook::getEntry: no such entry.\n";
return NoSuchEntry;
} else {
if(data->get((QCString)ENTRY_SECTION+'/'+key.getKey(), section))
{
kdDebug(GUARD, KAB_KDEBUG_AREA) <<
"AddressBook::getEntry: done." << endl;
return NoError;
} else {
return InternError;
}
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::getEntries(list<Entry>& thelist)
{
// ###########################################################################
StringKabKeyMap::iterator pos;
Entry entry;
// -----
thelist.erase(thelist.begin(), thelist.end());
kdDebug(!thelist.empty(), KAB_KDEBUG_AREA)
<< "AddressBook::getEntries: warning - non-empty value list!" << endl;
for(pos=entries->begin(); pos!=entries->end(); ++pos)
{
if(getEntry((*pos).second, entry))
{
thelist.push_back(entry);
} else {
return InternError;
}
}
// -----
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::getKey(int index, KabKey& key)
{
// ###########################################################################
StringKabKeyMap::iterator pos;
// -----
if((unsigned)index<entries->size())
{
pos=entries->begin();
advance(pos, index);
key=(*pos).second;
return NoError;
} else {
return NoSuchEntry;
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::getIndex(const KabKey& key, int& index)
{
register bool GUARD; GUARD=true;
// ###########################################################################
StringKabKeyMap::iterator pos;
// -----
index=0;
for(pos=entries->begin(); pos!=entries->end(); ++pos)
{
kdDebug() << (*pos).second.getKey().data() << " <--> " <<
key.getKey().data() << endl;
if((*pos).second==key) break;
++index;
}
kdDebug(pos==entries->end(), KAB_KDEBUG_AREA) <<
"AddressBook::getIndex: no such key." << endl;
if(pos==entries->end())
{
return NoSuchEntry;
} else {
return NoError;
}
// ###########################################################################
}
Section*
kdelibs'AddressBook::entrySection() (./kdelibs/kab/addressbook.cc:769)
AddressBook::entrySection()
{
// ###########################################################################
Section* section;
// -----
if(!data->get(ENTRY_SECTION, section))
{
return 0;
} else {
return section;
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::add(const Entry& entry, KabKey& key, bool update)
{
bool GUARD; GUARD=true;
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::add: called." << endl;
// ###########################################################################
Section* theEntries=entrySection();
Section* newEntry;
KabKey nextKey;
ErrorCode locked;
ErrorCode rc;
// -----
if(theEntries==0)
{
kdDebug() << "AddressBook::add: no entries section." << endl;
return NoFile;
}
newEntry=new Section;
if(newEntry==0)
{
KMessageBox::error(this,
i18n("Cannot initialize local variables."),
i18n("Out of memory"));
kapp->quit(); // It is critical, but will possibly never happen.
return InternError; // shut the compiler up...
}
// ----- lock the file:
locked=lock();
switch(locked)
{
case PermDenied:
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::add: permission denied." << endl;
return PermDenied; // cannot get r/w mode
case Locked:
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::add: db is already in r/w mode." << endl;
break;
case NoError:
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::add: got writing permissions." << endl;
break;
default:
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::add: unknown response, exiting." << endl;
return InternError;
}
// -----
if(makeSectionFromEntry(entry, *newEntry)==NoError)
{
nextKey=nextAvailEntryKey();
if(!theEntries->add(nextKey.getKey(), newEntry))
{
kDebugInfo("AddressBook::add: Cannot insert section.");
rc=InternError;
} else {
key=nextKey;
rc=NoError;
}
if(update) updateMirrorMap();
} else {
rc=InternError;
}
if(locked!=Locked)
{ // ----- unlock the file here:
kdDebug(GUARD, KAB_KDEBUG_AREA)
<< "AddressBook::add: dropped writing permissions." << endl;
locked=unlock();
}
// -----
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::add: done." << endl;
if(locked!=NoError)
{
return locked;
}
if(rc!=NoError)
{
return rc;
}
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::change(const KabKey& key, const Entry& entry)
{
// ###########################################################################
Section* theEntries=entrySection();
Section* oldEntry;
ErrorCode locked;
ErrorCode rc;
// -----
if(theEntries==0)
{
return NoFile;
}
// ----- lock the file:
locked=lock();
if(locked==PermDenied)
{
return PermDenied; // cannot get r/w mode
}
// -----
if(!theEntries->find(key.getKey(), oldEntry))
{
rc=NoSuchEntry;
} else {
oldEntry->clear();
rc=makeSectionFromEntry(entry, *oldEntry);
}
// -----
if(locked!=PermDenied)
{ // ----- unlock the file here:
locked=unlock();
}
if(locked==NoError)
{
return rc;
} else {
return locked;
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::remove(const KabKey& key)
{
// ###########################################################################
Section *theEntries=entrySection();
ErrorCode locked;
ErrorCode rc;
// -----
if(theEntries==0)
{
return NoFile;
}
// ----- lock the file:
locked=lock();
if(locked==PermDenied)
{
return PermDenied; // cannot get r/w mode
}
// -----
if(theEntries->remove(key.getKey()))
{
rc=NoError;
} else {
rc=NoSuchEntry;
}
// -----
if(locked!=PermDenied)
{ // ----- unlock the file here:
locked=unlock();
}
if(locked==NoError)
{
return rc;
} else {
return locked;
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::lock()
{
// ###########################################################################
if(!data->isRO()) return Locked;
if(data->setFileName(data->fileName(), false, false))
{
return NoError;
} else {
KMessageBox::information(this,
i18n("The file you wanted to change could not be locked.\n"
"It is probably in use by another application or read-only."),
i18n("File error"));
return PermDenied;
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::unlock()
{
// ###########################################################################
if(data->isRO()) return PermDenied;
if(data->setFileName(data->fileName(), true, true))
{
return NoError;
} else {
return InternError;
}
// ###########################################################################
}
KabKey
kdelibs'AddressBook::nextAvailEntryKey() (./kdelibs/kab/addressbook.cc:975)
AddressBook::nextAvailEntryKey()
{
// ###########################################################################
int max=0;
int temp;
Section::StringSectionMap::iterator pos;
Section *section=entrySection();
KabKey key;
QCString dummy;
bool good=true;
// -----
if(section!=0)
{
for(pos=section->sectionsBegin(); pos!=section->sectionsEnd(); ++pos)
{
temp=0;
temp=(*pos).first.toInt(&good);
if(!good)
{
kDebugInfo("AddressBook::nextAvailEntryKey: non-integer entry "
"key.");
}
if(temp>max)
{
max=temp;
}
}
}
// -----
dummy.setNum(++max);
key.setKey(dummy);
// CHECK(key.getKey().toInt(&good)==max);
return key;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::updateMirrorMap()
{
register bool GUARD; GUARD=true;
// ###########################################################################
kdDebug(GUARD, KAB_KDEBUG_AREA) <<
"AddressBook::updateMirrorMap: updating mirror map.\n";
QString key;
Entry entry;
ErrorCode ec;
KabKey kk;
Section *section=entrySection();
Section::StringSectionMap::iterator pos;
// -----
entries->erase(entries->begin(), entries->end());
if(section==0)
{
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::updateMirrorMap: done, "
"no file loaded." << endl;
return NoError;
}
for(pos=section->sectionsBegin(); pos!=section->sectionsEnd(); ++pos)
{
if(makeEntryFromSection((*pos).second, entry)!=NoError)
{
// return InternError; // it is saver to continue without a key
}
key="";
ec=literalName(entry, key, true, false);
if(key.isEmpty() || ec!=NoError)
{
key=i18n("(empty entry)");
}
key+=(*pos).first; // append the section name to make the key unique
kk.setKey((*pos).first);
entries->insert(StringKabKeyMap::value_type(key, kk));
}
// -----
kdDebug(GUARD, KAB_KDEBUG_AREA) << "AddressBook::updateMirrorMap: done."
<< endl;
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::makeEntryFromSection(Section* section, Entry& entry)
{
// ###########################################################################
// -----
Section *addresses;
Section *addressSection;
Section::StringSectionMap::iterator pos;
KeyValueMap *keys;
Entry temp;
Entry::Address address;
Entry::Address addressDummy;
int count;
// ----- create the aggregats:
const QCString StringKeys[]= {
"title",
"rank",
"fn",
"nameprefix",
"firstname",
"middlename",
"lastname",
"comment",
"user1",
"user2",
"user3",
"user4"
};
QString* StringValues[]= {
&temp.title,
&temp.rank,
&temp.fn,
&temp.nameprefix,
&temp.firstname,
&temp.middlename,
&temp.lastname,
&temp.comment,
&temp.user1,
&temp.user2,
&temp.user3,
&temp.user4
};
const int StringKeySize=sizeof(StringKeys)/sizeof(StringKeys[0]);
const QCString StringListKeys[]= {
"talk",
"emails",
"keywords",
"telephone",
"URLs"
};
QStringList* StringListValues[]= {
&temp.talk,
&temp.emails,
&temp.keywords,
&temp.telephone,
&temp.URLs
};
const int StringListKeySize=sizeof(StringListKeys)/sizeof(StringListKeys[0]);
// ----- first parse "addresses" subsection:
if(!section->find(ADDRESS_SUBSECTION, addresses))
{
return InternError; // no subsection called "addresses"
}
for(pos=addresses->sectionsBegin(); pos!=addresses->sectionsEnd(); ++pos)
{
if(!addresses->find((*pos).first, addressSection))
{
return InternError; // no section we have an iterator for?
}
keys=addressSection->getKeys();
address=addressDummy; // clean it up
if(makeAddressFromMap(keys, address)==AddressBook::NoError)
{
// ----- add the address to the list of addresses:
temp.addresses.push_back(address);
} else {
kdDebug(KAB_KDEBUG_AREA)
<< "AddressBook::makeEntryFromSection: cannot find all fields "
<< "in an address subsection." << endl;
}
}
// ----- now parse all other fields directly:
keys=section->getKeys();
for(count=0; count<StringKeySize; ++count)
{
if(!keys->get(StringKeys[count], *StringValues[count]))
{
kdDebug(KAB_KDEBUG_AREA)
<< "AddressBook::makeEntryFromSection: error: could not get "
<< "value for key " << (const char*)StringKeys[count]
<< "." << endl;
}
}
for(count=0; count<StringListKeySize; ++count)
{
if(!keys->get(StringListKeys[count], *StringListValues[count]))
{
kdDebug(KAB_KDEBUG_AREA)
<< "AddressBook::makeEntryFromSection: error: could not get "
<< "value for key " << (const char*)StringListKeys[count]
<< "." << endl;
}
}
// ----- finally get the birthday:
keys->get("birthday", temp.birthday); // this may return false (no date)
// -----
entry=temp;
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::makeAddressFromMap(KeyValueMap* keys, Entry::Address& address)
{
// ###########################################################################
const QCString Keys[]= {
"headline",
"position",
"org",
"orgunit",
"orgsubunit",
// "role",
"deliverylabel",
"address",
"zip",
"town",
"country",
"state"
};
QString* strings[]= {
&address.headline,
&address.position,
&address.org,
&address.orgUnit,
&address.orgSubUnit,
// &address.role,
&address.deliveryLabel,
&address.address,
&address.zip,
&address.town,
&address.country,
&address.state
};
const int Size=sizeof(Keys)/sizeof(Keys[0]);
int count;
// -----
for(count=0; count<Size; ++count)
{
if(!keys->get(Keys[count], *strings[count]))
{
debug("AddressBook::makeAddressFromSection: error: could not get "
"value for key %s.", (const char*)Keys[count]);
}
}
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::makeSectionFromEntry(const Entry& entry, Section& section)
{
// ###########################################################################
list<Entry::Address>::const_iterator addPos;
Section *addresses=0;
Section *address=0;
QCString key; // used for creating address subsection keys
int count=0; // counts the addresses
KeyValueMap *keys;
// ----- prepare the section object:
section.clear();
// ----- first create "addresses" subsection:
if(!section.add(ADDRESS_SUBSECTION))
{
kDebugInfo("AddressBook::makeSectionFromEntry: cannot create %s "
"subsection.", ADDRESS_SUBSECTION);
return InternError;
}
if(!section.find(ADDRESS_SUBSECTION, addresses))
{
kDebugInfo("AddressBook::makeSectionFromEntry: cannot get new section.");
return InternError;
}
// ----- now insert addresses:
for(addPos=entry.addresses.begin(); addPos!=entry.addresses.end(); ++addPos)
{
++count;
key.setNum(count);
if(!addresses->add(key))
{
kDebugInfo("AddressBook::makeSectionFromEntry: cannot create address "
"subsection %s.", (const char*)key);
return InternError;
}
if(!addresses->find(key, address))
{
kDebugInfo("AddressBook::makeSectionFromEntry: cannot get new "
"subsection.");
return InternError;
}
keys=address->getKeys();
// ----- now insert keys into address:
if(!keys->insert("headline", (*addPos).headline) ||
!keys->insert("position", (*addPos).position) ||
!keys->insert("org", (*addPos).org) ||
!keys->insert("orgunit", (*addPos).orgUnit) ||
!keys->insert("orgsubunit", (*addPos).orgSubUnit) ||
// !keys->insert("role", (*addPos).role) ||
!keys->insert("deliverylabel", (*addPos).deliveryLabel) ||
!keys->insert("address", (*addPos).address) ||
!keys->insert("zip", (*addPos).zip) ||
!keys->insert("town", (*addPos).town) ||
!keys->insert("country", (*addPos).country) ||
!keys->insert("state", (*addPos).state))
{
kDebugInfo("AddressBook::makeSectionFromEntry: cannot completely "
"create address subsection.");
return InternError;
}
}
// ----- now add the other fields:
keys=section.getKeys();
if(!keys->insert("title", entry.title) ||
!keys->insert("rank", entry.rank) ||
!keys->insert("fn", entry.fn) ||
!keys->insert("nameprefix", entry.nameprefix) ||
!keys->insert("firstname", entry.firstname) ||
!keys->insert("middlename", entry.middlename) ||
!keys->insert("lastname", entry.lastname) ||
!keys->insert("birthday", entry.birthday) ||
!keys->insert("comment", entry.comment) ||
!keys->insert("talk", entry.talk) ||
!keys->insert("emails", entry.emails) ||
!keys->insert("keywords", entry.keywords) ||
!keys->insert("telephone", entry.telephone) ||
!keys->insert("URLs", entry.URLs) ||
!keys->insert("user1", entry.user1) ||
!keys->insert("user2", entry.user2) ||
!keys->insert("user3", entry.user3) ||
!keys->insert("user4", entry.user4))
{
kDebugInfo("AddressBook::makeEntryFromSection: cannot insert all fields of the "
"entry into its section!");
return InternError;
}
// -----
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::createNew(const QString& filename)
{
// ###########################################################################
const QString KabTemplateFile=locate("data", "kab/template.kab");
debug("AddressBook::createNew: template file is \"%s\".",
(const char*)KabTemplateFile.utf8());
QConfigDB db;
// -----
if(KabTemplateFile.isEmpty()
|| !db.setFileName(KabTemplateFile, true, true))
{
KMessageBox::error(this,
i18n("Cannot find kab's template file.\n"
"You cannot create new files."),
i18n("File error"));
return InternError;
}
if(!db.load())
{
KMessageBox::error(this,
i18n("Cannot read kab's template file.\n"
"You cannot create new files."),
i18n("Format error"));
return InternError;
}
if(!db.setFileName(filename, false, false))
{
KMessageBox::error(this,
i18n("Cannot create the file\n\"")
+filename+"\"\n"+
i18n("Could not create the new file."),
i18n("File error"));
return PermDenied;
}
if(!db.save())
{
KMessageBox::error(this,
i18n("Cannot save the file\n\"")
+filename+"\"\n"+
i18n("Could not create the new file."),
i18n("File error"));
return InternError;
}
// -----
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::createConfigFile()
{
// ###########################################################################
const QString ConfigTemplateFile=locate("data", "kab/template.config");
debug("AddressBook::createConfigFile: config template file is \"%s\".",
(const char*)ConfigTemplateFile.utf8());
const QString filename=baseDir()+"/"+STD_CONFIGFILENAME;
QConfigDB db;
// -----
if(ConfigTemplateFile.isEmpty()
|| !db.setFileName(ConfigTemplateFile, true, true))
{
KMessageBox::error(this,
i18n("Cannot find kab's configuration template file.\n"
"kab cannot be configured."),
i18n("File error"));
return InternError;
}
if(!db.load())
{
KMessageBox::error(this,
i18n("Cannot read kab's configuration template file.\n"
"kab cannot be configured."),
i18n("File error"));
return InternError;
}
if(!db.setFileName(filename, false, false))
{
KMessageBox::error(this,
i18n("Cannot create the file\n\"")
+filename+"\"\n"+
i18n("Could not create the new configuration file."),
i18n("File error"));
return PermDenied;
}
if(!db.save())
{
KMessageBox::error(this,
i18n("Cannot save the file\n\"")
+filename+"\"\n"+
i18n("Could not create the new configuration file."),
i18n("File error"));
return InternError;
}
// -----
return NoError;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::loadConfigFile()
{
// ###########################################################################
QString file;
// -----
file=baseDir()+"/"+STD_CONFIGFILENAME;
if(config->setFileName(file, true, true))
{
if(config->load())
{
return NoError;
} else {
KMessageBox::information(this,
i18n("Cannot load kab's local configuration file,\n"
"possibly there is a formation error.\n"
"kab cannot be configured."),
i18n("File error"));
return InternError;
}
} else {
KMessageBox::information(this,
i18n("Cannot find kab's local configuration file.\n"
"kab cannot be configured."),
i18n("File error"));
return NoSuchFile;
}
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::makeVCardFromEntry(const Entry&, QString)
{
// ###########################################################################
return NotImplemented;
// ###########################################################################
}
AddressBook::ErrorCode
AddressBook::makeEntryFromVCard(const QString&, Entry&)
{
// ###########################################################################
return NotImplemented;
// ###########################################################################
}
QString
kdelibs'AddressBook::getStandardFilename() (./kdelibs/kab/addressbook.cc:1452)
AddressBook::getStandardFilename()
{
// ###########################################################################
QString temp;
// -----
temp=baseDir();
temp+=QString("/")+STD_USERFILENAME;
return temp;
// ###########################################################################
}
QString
kdelibs'AddressBook::baseDir() (./kdelibs/kab/addressbook.cc:1464)
AddressBook::baseDir()
{
// ###########################################################################
QString dir;
// -----
// dir=KGlobal::dirs()->saveLocation("data", KAB_LOCALDIR, false);
dir=KGlobal::dirs()->saveLocation("data", "kab", true);
if(dir==QString::null)
{
KMessageBox::information(this,
i18n("The directory where user specific data for the\n"
"addressbook application is stored does not exist.\n"
"The program will try to create\n \"")
+dir+"\"\n"+
i18n("and store all local files in this directory."),
i18n("First usage"));
// ----- create the directory and check success:
dir=KGlobal::dirs()->saveLocation("data", KAB_LOCALDIR, true);
if(dir==QString::null)
{
KMessageBox::information(this,
i18n("The directory could not be created.\n"
"Probably you do not have used KDE before, so\n"
"you do not have a local \".kde\" directory\n"
"in your home directory. Run the KDE filemanager\n"
"kfm once to automatically create it.\n"
"kab will continue, but no file will be loaded."),
i18n("Error creating directory"));
state=PermDenied;
return QString::null;
} else { // ----- just for interactivity:
KMessageBox::information(this,
i18n("The directory has been created."),
i18n("Directory created"));
return dir;
}
} else {
return dir;
}
// ###########################################################################
}
kdelibs'AddressBook::phoneType() (./kdelibs/kab/addressbook.cc:1506)
QString AddressBook::phoneType(AddressBook::Telephone phone)
{
switch(phone)
{
case Fixed: return i18n("fixed"); break;
case Mobile: return i18n("mobile"); break;
case Fax: return i18n("fax"); break;
case Modem: return i18n("modem"); break;
default: return i18n("general");
}
}
kdelibs'AddressBook::externalChange() (./kdelibs/kab/addressbook.cc:1518)
void AddressBook::externalChange()
{
updateMirrorMap();
}
kdelibs'AddressBook::configurationSection() (./kdelibs/kab/addressbook.cc:1523)
Section* AddressBook::configurationSection()
{
Section *section;
if(data!=0)
{
if(data->get(LOCAL_CONFIG_SECTION, section))
{
return section;
} else {
return 0;
}
} else {
return 0;
}
}