[ekiga] Call history: enforce the limit to 100



commit 5d8ca54e8351eaf3e6bdf258cad2b9a0b8f7ddd7
Author: Julien Puydt <jpuydt free fr>
Date:   Tue Jul 3 10:28:03 2012 +0200

    Call history: enforce the limit to 100
    
    Notice: the gui doesn't update correctly yet...

 .../components/call-history/history-book.cpp       |   36 ++++++++++++++++++-
 lib/engine/components/call-history/history-book.h  |    5 +++
 2 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/lib/engine/components/call-history/history-book.cpp b/lib/engine/components/call-history/history-book.cpp
index 40752e5..7996501 100644
--- a/lib/engine/components/call-history/history-book.cpp
+++ b/lib/engine/components/call-history/history-book.cpp
@@ -104,7 +104,7 @@ History::Book::get_name () const
 void
 History::Book::add (xmlNodePtr node)
 {
-  add_contact (ContactPtr (new Contact (core, doc, node)));
+  common_add (ContactPtr (new Contact (core, doc, node)));
 }
 
 void
@@ -126,7 +126,9 @@ History::Book::add (const std::string & name,
 
     save ();
 
-    add_contact (contact);
+    common_add (contact);
+
+    enforce_size_limit();
   }
 }
 
@@ -201,3 +203,33 @@ History::Book::on_cleared_call (boost::shared_ptr<Ekiga::CallManager> /*manager*
        call->get_duration (),
        (call->is_outgoing ()?PLACED:RECEIVED));
 }
+
+void
+History::Book::common_add (ContactPtr contact)
+{
+  add_contact (contact);
+  ordered_contacts.push_back (contact);
+}
+
+void
+History::Book::enforce_size_limit()
+{
+  bool flag = false;
+
+  while (ordered_contacts.size() > 100) {
+
+    ContactPtr contact = ordered_contacts.front ();
+    ordered_contacts.pop_front();
+    xmlNodePtr node = contact->get_node ();
+    contact->removed();
+    xmlUnlinkNode(node);
+    xmlFreeNode(node);
+    flag = true;
+  }
+
+  if (flag) {
+
+    save();
+    updated();
+  }
+}
diff --git a/lib/engine/components/call-history/history-book.h b/lib/engine/components/call-history/history-book.h
index c531b59..bbda076 100644
--- a/lib/engine/components/call-history/history-book.h
+++ b/lib/engine/components/call-history/history-book.h
@@ -101,8 +101,13 @@ namespace History
 			  boost::shared_ptr<Ekiga::Call> call,
 			  std::string message);
 
+    void common_add (ContactPtr contact);
+
+    void enforce_size_limit();
+
     Ekiga::ServiceCore &core;
     boost::shared_ptr<xmlDoc> doc;
+    std::list<ContactPtr> ordered_contacts;
   };
 
   typedef boost::shared_ptr<Book> BookPtr;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]