summaryrefslogtreecommitdiffstats
path: root/src/address_book.h
diff options
context:
space:
mode:
authorMichal Kubecek <mkubecek@suse.cz>2015-04-13 09:21:39 +0200
committerMichal Kubecek <mkubecek@suse.cz>2015-04-13 09:21:39 +0200
commite2bc6f4153813cc570ae814c8ddb74628009b488 (patch)
treea40b171be1d859c2232ccc94f758010f9ae54d3c /src/address_book.h
downloadtwinkle-e2bc6f4153813cc570ae814c8ddb74628009b488.tar
twinkle-e2bc6f4153813cc570ae814c8ddb74628009b488.tar.gz
twinkle-e2bc6f4153813cc570ae814c8ddb74628009b488.tar.lz
twinkle-e2bc6f4153813cc570ae814c8ddb74628009b488.tar.xz
twinkle-e2bc6f4153813cc570ae814c8ddb74628009b488.zip
initial checkin
Check in contents of upstream 1.4.2 tarball, exclude generated files.
Diffstat (limited to 'src/address_book.h')
-rw-r--r--src/address_book.h125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/address_book.h b/src/address_book.h
new file mode 100644
index 0000000..5a54c14
--- /dev/null
+++ b/src/address_book.h
@@ -0,0 +1,125 @@
+/*
+ Copyright (C) 2005-2009 Michel de Boer <michel@twinklephone.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/**
+ * @file
+ * Local address book.
+ */
+
+#ifndef _ADDRESS_BOOK_H
+#define _ADDRESS_BOOK_H
+
+#include <string>
+#include <list>
+
+#include "user.h"
+#include "sockets/url.h"
+#include "threads/mutex.h"
+#include "utils/record_file.h"
+
+using namespace std;
+
+/** A single address card. */
+class t_address_card : public utils::t_record {
+public:
+ string name_last; /**< Last name. */
+ string name_first; /**< First name. */
+ string name_infix; /**< Infix name. */
+ string sip_address; /**< SIP address. */
+ string remark; /**< Remark. */
+
+ /**
+ * Get the display name derived from first, last and infix name.
+ * @return The display name.
+ */
+ string get_display_name(void) const;
+
+ virtual bool create_file_record(vector<string> &v) const;
+ virtual bool populate_from_file_record(const vector<string> &v);
+
+ /** Equality check. */
+ bool operator==(const t_address_card other) const;
+};
+
+/**
+ * A book containing address cards. The user can
+ * create different address books.
+ */
+class t_address_book : public utils::t_record_file<t_address_card> {
+private:
+ /** @name Cache for last searched name/url mapping */
+ //@{
+ mutable t_url last_url; /**< Last URL. */
+ mutable string last_name; /**< Lat name. */
+ //@}
+
+ /**
+ * Find a matching address for a url and cache the display name.
+ * @param user_config [in] The user profile.
+ * @param u [in] The url to find.
+ * @post If a matching address is found, then the URL and name are
+ * put in the cache. Otherwise the cache is cleared.
+ */
+ void find_address(t_user *user_config, const t_url &u) const;
+
+public:
+ /** Constructor. */
+ t_address_book();
+
+ /**
+ * Add an address.
+ * @param address [in] The address to be added.
+ */
+ void add_address(const t_address_card &address);
+
+ /**
+ * Delete an address.
+ * @return true, if the address was succesfully deleted.
+ * @return false, if the address does not exist.
+ */
+ bool del_address(const t_address_card &address);
+
+ /**
+ * Update an address.
+ * @param old_address [in] The address to be updated.
+ * @param new_address [in] The updated address information.
+ * @return true, if the update was successful.
+ * @return false, if the old address does not exist.
+ */
+ bool update_address(const t_address_card &old_address,
+ const t_address_card &new_address);
+
+ /**
+ * Find the display name for a SIP URL.
+ * @param user_config [in] The user profile.
+ * @param u [in] The SIP URL.
+ * @return The display name if a match was found.
+ * @return Empty string if no match can be found.
+ */
+ string find_name(t_user *user_config, const t_url &u) const;
+
+ /**
+ * Get the list of addresses.
+ * @return The list of addresses.
+ */
+ const list<t_address_card> &get_address_list(void) const;
+};
+
+extern t_address_book *ab_local;
+
+#endif