00001
00002
00003
00004
00005
00006
00007
00008 #include <iostream>
00009 using namespace std;
00010 #include "directory.h"
00011 #include "qdatetime.h"
00012 #include "qdir.h"
00013 #include <mythtv/mythcontext.h>
00014 #include <mythtv/mythdbcon.h>
00015
00016
00017 static int counter = 0;
00018
00020
00022
00023 DirEntry::DirEntry(QString nn, QString uri, QString fn, QString sn, QString ph, bool ohl)
00024 {
00025 NickName = nn;
00026 FirstName = fn;
00027 Surname = sn;
00028 Uri = uri;
00029 PhotoFile = ph;
00030 id = counter++;
00031 SpeedDial = false;
00032 inDatabase = false;
00033 changed = true;
00034 onHomeLan = ohl;
00035 dbId = -1;
00036 }
00037
00038
00039 DirEntry::DirEntry(DirEntry *Original)
00040 {
00041 NickName = Original->NickName;
00042 FirstName = Original->FirstName;
00043 Surname = Original->Surname;
00044 Uri = Original->Uri;
00045 PhotoFile = Original->PhotoFile;
00046 onHomeLan = Original->onHomeLan;
00047 id = counter++;
00048 inDatabase = false;
00049 changed = true;
00050 dbId = -1;
00051 TreeNode = 0;
00052 SpeeddialNode = 0;
00053 }
00054
00055
00056 DirEntry::~DirEntry()
00057 {
00058 }
00059
00060
00061 bool DirEntry::urlMatches(QString s)
00062 {
00063
00064
00065
00066 return (Uri == s) ? true : false;
00067 }
00068
00069
00070
00071 int getAlphaSortId(QString s)
00072 {
00073 int v=0;
00074 s = s.lower();
00075 int len = s.length();
00076
00077
00078
00079 v |= ((len>0) ? (s.at(0).unicode() << 24) : 0);
00080 v |= ((len>1) ? (s.at(1).unicode() << 16) : 0);
00081 v |= ((len>2) ? (s.at(2).unicode() << 8) : 0);
00082 v |= ((len>3) ? (s.at(3).unicode() << 0) : 0);
00083
00084 return v;
00085 }
00086
00087 void DirEntry::writeTree(GenericTree *tree_to_write_to, GenericTree *sdTree)
00088 {
00089 GenericTree *sub_node;
00090
00091 if (tree_to_write_to)
00092 {
00093 sub_node = tree_to_write_to->addNode(NickName, 0, true);
00094 sub_node->setAttribute(0, TA_DIRENTRY);
00095 sub_node->setAttribute(1, id);
00096 sub_node->setAttribute(2, getAlphaSortId(NickName));
00097 TreeNode = sub_node;
00098 }
00099
00100 if ((SpeedDial) && (sdTree != 0))
00101 {
00102
00103
00104 sub_node = sdTree->addNode(NickName, 0, true);
00105 sub_node->setAttribute(0, TA_SPEEDDIALENTRY);
00106 sub_node->setAttribute(1, id);
00107 sub_node->setAttribute(2, getAlphaSortId(NickName));
00108 sub_node->setAttribute(3, ICON_PRES_UNKNOWN);
00109 SpeeddialNode = sub_node;
00110 }
00111 }
00112
00113
00114 void DirEntry::updateYourselfInDB(QString Dir)
00115 {
00116 QString thequery;
00117 MSqlQuery query(MSqlQuery::InitCon());
00118
00119 if (!inDatabase)
00120 {
00121 thequery = QString("INSERT INTO phonedirectory (nickname,firstname,surname,"
00122 "url,directory,photofile,speeddial,onhomelan) VALUES "
00123 "(\"%1\",\"%2\",\"%3\",\"%4\",\"%5\",\"%6\",%7,%8);")
00124 .arg(NickName.latin1()).arg(FirstName.latin1())
00125 .arg(Surname.latin1()).arg(Uri.latin1())
00126 .arg(Dir.latin1()).arg(PhotoFile.latin1())
00127 .arg(SpeedDial).arg(onHomeLan);
00128 query.exec(thequery);
00129
00130 thequery = QString("SELECT MAX(intid) FROM phonedirectory ;");
00131 query.exec(thequery);
00132
00133 if ((query.isActive()) && (query.size() == 1))
00134 {
00135 query.next();
00136 dbId = query.value(0).toUInt();
00137 inDatabase = true;
00138 changed = false;
00139 }
00140 else
00141 cerr << "Mythphone: Something is up with the database\n";
00142 }
00143 else if (changed)
00144 {
00145 thequery = QString("UPDATE phonedirectory "
00146 "SET nickname=\"%1\", "
00147 "firstname=\"%2\", "
00148 "surname=\"%3\", "
00149 "directory=\"%4\", "
00150 "url=\"%5\", "
00151 "photofile=\"%6\", "
00152 "speeddial=%7, "
00153 "onhomelan=%8 "
00154 "WHERE intid=%9 ;")
00155 .arg(NickName.latin1()).arg(FirstName.latin1())
00156 .arg(Surname.latin1()).arg(Dir.latin1()).arg(Uri.latin1())
00157 .arg(PhotoFile.latin1()).arg(SpeedDial).arg(onHomeLan)
00158 .arg(dbId);
00159 query.exec(thequery);
00160 changed = false;
00161 }
00162 }
00163
00164
00165 void DirEntry::deleteYourselfFromDB()
00166 {
00167 QString thequery;
00168 MSqlQuery query(MSqlQuery::InitCon());
00169
00170 if (inDatabase)
00171 {
00172 thequery = QString("DELETE FROM phonedirectory "
00173 "WHERE intid=%1 ;").arg(dbId);
00174 query.exec(thequery);
00175 }
00176 }
00177
00178
00179
00180
00182
00184
00185 Directory::Directory(QString Name):QPtrList<DirEntry>()
00186 {
00187 name = Name;
00188 }
00189
00190 Directory::~Directory()
00191 {
00192 DirEntry *p;
00193 while ((p = first()) != 0)
00194 {
00195 remove();
00196 delete p;
00197 }
00198 }
00199
00200 DirEntry *Directory::fetchById(int id)
00201 {
00202 DirEntry *it;
00203 for (it=first(); it; it=next())
00204 if (it->getId() == id)
00205 return it;
00206 return 0;
00207 }
00208
00209 void Directory::writeTree(GenericTree *tree_to_write_to, GenericTree *sdTree)
00210 {
00211 DirEntry *it;
00212 for (it=first(); it; it=next())
00213 it->writeTree(tree_to_write_to, sdTree);
00214 }
00215
00216
00217 int Directory::compareItems(QPtrCollection::Item s1, QPtrCollection::Item s2)
00218 {
00219 DirEntry *d1 = (DirEntry *)s1;
00220 DirEntry *d2 = (DirEntry *)s2;
00221
00222 return (getAlphaSortId(d1->getNickName()) - getAlphaSortId(d2->getNickName()));
00223 }
00224
00225 DirEntry *Directory::getDirEntrybyDbId(int dbId)
00226 {
00227 DirEntry *it;
00228 for (it=first(); it; it=next())
00229 if (it->getDbId() == dbId)
00230 return it;
00231 return 0;
00232 }
00233
00234 DirEntry *Directory::getDirEntrybyUrl(QString Url)
00235 {
00236 DirEntry *it;
00237 for (it=first(); it; it=next())
00238 if (it->getUri() == Url)
00239 return it;
00240 return 0;
00241 }
00242
00243 void Directory::saveChangesinDB()
00244 {
00245 DirEntry *it;
00246 for (it=first(); it; it=next())
00247 {
00248 it->updateYourselfInDB(name);
00249 }
00250 }
00251
00252 void Directory::deleteEntry(DirEntry *Entry)
00253 {
00254 Entry->deleteYourselfFromDB();
00255
00256 if (find(Entry) != -1)
00257 {
00258 remove();
00259 delete Entry;
00260 }
00261 }
00262
00263 void Directory::AddAllEntriesToList(QStrList &l, bool SpeeddialsOnly)
00264 {
00265 DirEntry *it;
00266 for (it=first(); it; it=next())
00267 if ((!SpeeddialsOnly) || (it->isSpeedDial()))
00268 l.append(it->getUri());
00269 return;
00270 }
00271
00272 void Directory::ChangePresenceStatus(QString Uri, int Status, QString StatusString, bool SpeeddialsOnly)
00273 {
00274 DirEntry *it;
00275 for (it=first(); it; it=next())
00276 if ((it->urlMatches(Uri)) &&
00277 ((!SpeeddialsOnly) || (it->isSpeedDial())))
00278 {
00279 {
00280 if (!SpeeddialsOnly)
00281 {
00282
00283
00284
00285 (it->getTreeNode())->setString(it->getNickName() + " (" + StatusString + ")");
00286 }
00287
00288 (it->getSpeeddialNode())->setAttribute(3, Status);
00289 (it->getSpeeddialNode())->setString(it->getNickName() + " (" + StatusString + ")");
00290 }
00291 }
00292 }
00293
00294
00295
00297
00299
00300 CallRecord::CallRecord(QString dn, QString uri, bool callIn, QString ts)
00301 {
00302 DisplayName = dn;
00303 Uri = uri;
00304 id = counter++;
00305 timestamp = ts;
00306 Duration = 0;
00307 DirectionIn = callIn;
00308 inDatabase = false;
00309 changed = true;
00310 dbId = -1;
00311 }
00312
00313
00314 CallRecord::CallRecord(CallRecord *Original)
00315 {
00316 DisplayName = Original->DisplayName;
00317 Uri = Original->Uri;
00318 timestamp = Original->timestamp;
00319 Duration = Original->Duration;
00320 DirectionIn = Original->DirectionIn;
00321 id = counter++;
00322 inDatabase = false;
00323 changed = true;
00324 dbId = -1;
00325 }
00326
00327
00328 CallRecord::CallRecord(DirEntry *Original, bool callIn, QString ts)
00329 {
00330 DisplayName = Original->getNickName();
00331 Uri = Original->getUri();
00332 id = counter++;
00333 timestamp = ts;
00334 Duration = 0;
00335 DirectionIn = callIn;
00336 inDatabase = false;
00337 changed = true;
00338 dbId = -1;
00339 }
00340
00341
00342 CallRecord::~CallRecord()
00343 {
00344 }
00345
00346
00347 void CallRecord::writeTree(GenericTree *tree_to_write_to)
00348 {
00349 QString label = DisplayName;
00350 if (label.length() == 0)
00351 label = Uri;
00352 if (timestamp.length() > 0)
00353 {
00354 QDateTime dt = QDateTime::fromString(timestamp);
00355 QString ts = dt.toString("dd-MMM hh:mm");
00356 QString dur = QString(" (%1 min)").arg(Duration/60);
00357
00358
00359
00360
00361 if (label.length() > 25)
00362 label.replace(22, 3, "...");
00363 label.leftJustify(25);
00364 ts.prepend(" ");
00365 label.replace(25, ts.length(), ts);
00366 label += dur;
00367 }
00368 GenericTree *sub_node = tree_to_write_to->addNode(label, 0, true);
00369 sub_node->setAttribute(0, TA_CALLHISTENTRY);
00370 sub_node->setAttribute(1, id);
00371 sub_node->setAttribute(2, -id);
00372 }
00373
00374
00375 void CallRecord::updateYourselfInDB()
00376 {
00377 QString thequery;
00378 MSqlQuery query(MSqlQuery::InitCon());
00379
00380 if (!inDatabase)
00381 {
00382 thequery = QString("INSERT INTO phonecallhistory (displayname,url,timestamp,"
00383 "duration, directionin, directoryref) VALUES "
00384 "(\"%1\",\"%2\",\"%3\",%4,%5,%6);")
00385 .arg(DisplayName.latin1()).arg(Uri.latin1())
00386 .arg(timestamp.latin1()).arg(Duration)
00387 .arg(DirectionIn).arg(0);
00388 query.exec(thequery);
00389
00390 thequery = QString("SELECT MAX(recid) FROM phonecallhistory ;");
00391 query.exec(thequery);
00392
00393 if ((query.isActive()) && (query.size() == 1))
00394 {
00395 query.next();
00396 dbId = query.value(0).toUInt();
00397 inDatabase = true;
00398 changed = false;
00399 }
00400 else
00401 cerr << "Mythphone: Something is up with the database\n";
00402 }
00403 else if (changed)
00404 {
00405 thequery = QString("UPDATE phonecallhistory "
00406 "SET displayname=\"%1\", "
00407 "url=\"%2\", "
00408 "timestamp=\"%3\", "
00409 "duration=%4, "
00410 "directionin=%5, "
00411 "directoryref=%6 "
00412 "WHERE recid=%7 ;")
00413 .arg(DisplayName.latin1()).arg(Uri.latin1())
00414 .arg(timestamp.latin1()).arg(Duration)
00415 .arg(DirectionIn).arg(0)
00416 .arg(dbId);
00417 query.exec(thequery);
00418 changed = false;
00419 }
00420 }
00421
00422
00423 void CallRecord::deleteYourselfFromDB()
00424 {
00425 QString thequery;
00426 MSqlQuery query(MSqlQuery::InitCon());
00427
00428 if (inDatabase)
00429 {
00430 thequery = QString("DELETE FROM phonecallhistory "
00431 "WHERE recid=%1 ;").arg(dbId);
00432 query.exec(thequery);
00433 }
00434 }
00435
00436
00437
00438
00439
00440
00441
00443
00445
00446 CallHistory::~CallHistory()
00447 {
00448 CallRecord *p;
00449 while ((p = first()) != 0)
00450 {
00451 remove();
00452 delete p;
00453 }
00454 }
00455
00456 CallRecord *CallHistory::fetchById(int id)
00457 {
00458 CallRecord *it;
00459 for (it=first(); it; it=next())
00460 if (it->getId() == id)
00461 return it;
00462 return 0;
00463 }
00464
00465 void CallHistory::writeTree(GenericTree *placed_tree, GenericTree *received_tree)
00466 {
00467 CallRecord *it;
00468 for (it=first(); it; it=next())
00469 {
00470 if (it->isIncoming())
00471 it->writeTree(received_tree);
00472 else
00473 it->writeTree(placed_tree);
00474 }
00475 }
00476
00477
00478 int CallHistory::compareItems(QPtrCollection::Item s1, QPtrCollection::Item s2)
00479 {
00480 CallRecord *d1 = (CallRecord *)s1;
00481 CallRecord *d2 = (CallRecord *)s2;
00482 QDateTime dt1 = QDateTime::fromString(d1->getTimestamp());
00483 QDateTime dt2 = QDateTime::fromString(d2->getTimestamp());
00484
00485 if (dt1 == dt2)
00486 return 0;
00487 return ((dt1 < dt2) ? 1 : -1);
00488 }
00489
00490 void CallHistory::saveChangesinDB()
00491 {
00492 CallRecord *it;
00493 for (it=first(); it; it=next())
00494 {
00495 it->updateYourselfInDB();
00496 }
00497 }
00498
00499 void CallHistory::deleteRecords()
00500 {
00501 CallRecord *it;
00502 for (it=first(); it; it=current())
00503 {
00504 it->deleteYourselfFromDB();
00505 remove();
00506 delete it;
00507 }
00508 }
00509
00510
00511
00513
00515
00516
00517 DirectoryContainer::DirectoryContainer()
00518 {
00519
00520 callHistory = new CallHistory();
00521 }
00522
00523
00524 DirectoryContainer::~DirectoryContainer()
00525 {
00526 saveChangesinDB();
00527
00528 Directory *p;
00529 while ((p = AllDirs.first()) != 0)
00530 {
00531 AllDirs.remove();
00532 delete p;
00533 }
00534
00535 delete callHistory;
00536 callHistory = 0;
00537 }
00538
00539
00540 void DirectoryContainer::Load()
00541 {
00542
00543 MSqlQuery query(MSqlQuery::InitCon());
00544 QString thequery = QString("SELECT intid, nickname,firstname,surname,"
00545 "url,directory,photofile,speeddial,onhomelan "
00546 "FROM phonedirectory "
00547 "ORDER BY intid ;");
00548 query.exec(thequery);
00549
00550 if(query.isActive() && query.size() > 0)
00551 {
00552 while(query.next())
00553 {
00554 QString Dir(query.value(5).toString());
00555 if (fetch(Dir) == 0)
00556 AllDirs.append(new Directory(Dir));
00557
00558 DirEntry *entry = new DirEntry(
00559 query.value(1).toString(),
00560 query.value(4).toString(),
00561 query.value(2).toString(),
00562 query.value(3).toString(),
00563 query.value(6).toString(),
00564 query.value(8).toInt());
00565 entry->setDbId(query.value(0).toInt());
00566 entry->setSpeedDial(query.value(7).toInt());
00567 entry->setDBUpToDate();
00568 AddEntry(entry, Dir, false);
00569 }
00570 }
00571 else
00572 cout << "mythphone: Nothing in your Directory -- ok?\n";
00573
00574
00575 thequery = QString("SELECT recid, displayname,url,timestamp,"
00576 "duration, directionin, directoryref "
00577 "FROM phonecallhistory "
00578 "ORDER BY recid ;");
00579 query.exec(thequery);
00580
00581 if(query.isActive() && query.size() > 0)
00582 {
00583 while(query.next())
00584 {
00585 CallRecord *entry = new CallRecord(
00586 query.value(1).toString(),
00587 query.value(2).toString(),
00588 query.value(5).toInt(),
00589 query.value(3).toString());
00590 entry->setDbId(query.value(0).toInt());
00591 entry->setDuration(query.value(4).toInt());
00592 entry->setDBUpToDate();
00593 AddToCallHistory(entry, false);
00594 }
00595 }
00596 else
00597 cout << "mythphone: Nothing in your Call History -- ok?\n";
00598 }
00599
00600 void DirectoryContainer::createTree()
00601 {
00602 TreeRoot = new GenericTree("directory root", 0);
00603 TreeRoot->setAttribute(0, TA_ROOT);
00604 TreeRoot->setAttribute(1, 0);
00605 TreeRoot->setAttribute(2, 0);
00606 }
00607
00608
00609
00610 Directory *DirectoryContainer::fetch(QString Dir)
00611 {
00612 Directory *it;
00613 for (it=AllDirs.first(); it; it=AllDirs.next())
00614 if (it->getName() == Dir)
00615 return it;
00616 return 0;
00617 }
00618
00619
00620 DirEntry *DirectoryContainer::fetchDirEntryById(int id)
00621 {
00622 Directory *it;
00623 DirEntry *p;
00624 for (it=AllDirs.first(); it; it=AllDirs.next())
00625 if ((p = it->fetchById(id)) != 0)
00626 return p;
00627 return 0;
00628 }
00629
00630 CallRecord *DirectoryContainer::fetchCallRecordById(int id)
00631 {
00632 return (callHistory->fetchById(id));
00633 }
00634
00635 void DirectoryContainer::AddEntry(DirEntry *entry, QString Dir, bool addToUITree)
00636 {
00637 Directory *dp = fetch(Dir);
00638 if (dp == 0)
00639 {
00640 dp = new Directory(Dir);
00641 AllDirs.append(dp);
00642 }
00643 dp->append(entry);
00644
00645 if (addToUITree)
00646 addToTree(entry, Dir);
00647 }
00648
00649
00650 void DirectoryContainer::ChangeEntry(DirEntry *entry, QString nn, QString Url, QString fn, QString sn, QString ph, bool OnHomeLan)
00651 {
00652 if (nn != 0)
00653 entry->setNickName(nn);
00654 if (Url != 0)
00655 entry->setUri(Url);
00656 if (fn != 0)
00657 entry->setFirstName(fn);
00658 if (sn != 0)
00659 entry->setSurname(sn);
00660 if (ph != 0)
00661 entry->setPhotoFile(ph);
00662
00663 entry->setOnHomeLan(OnHomeLan);
00664
00665
00666 findInTree(TreeRoot, 0, TA_DIRENTRY, 1, entry->getId());
00667
00668
00669
00670 }
00671
00672
00673 void DirectoryContainer::AddToCallHistory(CallRecord *entry, bool addToUITree)
00674 {
00675 GenericTree* Tree;
00676 callHistory->append(entry);
00677 if (addToUITree)
00678 {
00679 Tree = (entry->isIncoming()) ? receivedcallsTree : placedcallsTree;
00680 entry->writeTree(Tree);
00681 Tree->reorderSubnodes(2);
00682 }
00683 }
00684
00685
00686 void DirectoryContainer::clearCallHistory()
00687 {
00688
00689 callHistory->deleteRecords();
00690
00691
00692 receivedcallsTree->deleteAllChildren();
00693 placedcallsTree->deleteAllChildren();
00694 }
00695
00696
00697 QStrList DirectoryContainer::getDirectoryList(void)
00698 {
00699 QStrList l;
00700 Directory *it;
00701 for (it=AllDirs.first(); it; it=AllDirs.next())
00702 {
00703 l.append(it->getName());
00704 }
00705 return l;
00706 }
00707
00708
00709 void DirectoryContainer::writeTree()
00710 {
00711
00712
00713 speeddialTree = TreeRoot->addNode(QObject::tr("Speed Dials"), 0, true);
00714 speeddialTree->setAttribute(0, TA_DIR);
00715 speeddialTree->setAttribute(1, 0);
00716 speeddialTree->setAttribute(2, 0);
00717 voicemailTree = TreeRoot->addNode(QObject::tr("Voicemail"), 0, true);
00718 voicemailTree->setAttribute(0, TA_VMAIL);
00719 voicemailTree->setAttribute(1, 0);
00720 voicemailTree->setAttribute(2, 1);
00721 placedcallsTree = TreeRoot->addNode(QObject::tr("Placed Calls"), 0, true);
00722 placedcallsTree->setAttribute(0, TA_DIR);
00723 placedcallsTree->setAttribute(1, 0);
00724 placedcallsTree->setAttribute(2, 2);
00725 receivedcallsTree = TreeRoot->addNode(QObject::tr("Received Calls"), 0, true);
00726 receivedcallsTree->setAttribute(0, TA_DIR);
00727 receivedcallsTree->setAttribute(1, 0);
00728 receivedcallsTree->setAttribute(2, 2);
00729
00730
00731 callHistory->writeTree(placedcallsTree, receivedcallsTree);
00732
00733
00734 PutVoicemailInTree(voicemailTree);
00735
00736
00737 Directory *it;
00738 for (it=AllDirs.first(); it; it=AllDirs.next())
00739 {
00740 GenericTree *sub_node = TreeRoot->addNode(it->getName(), 0, true);
00741 sub_node->setAttribute(0, TA_DIR);
00742 sub_node->setAttribute(1, 0);
00743 sub_node->setAttribute(2, 3);
00744
00745 it->writeTree(sub_node, speeddialTree);
00746 }
00747 }
00748
00749
00750
00751 GenericTree *DirectoryContainer::addToTree(QString DirName)
00752 {
00753 Directory *dp = fetch(DirName);
00754 if (dp != 0)
00755 {
00756 GenericTree *sub_node = TreeRoot->addNode(DirName, 0, true);
00757 sub_node->setAttribute(0, TA_DIR);
00758 sub_node->setAttribute(1, 0);
00759 sub_node->setAttribute(2, 3);
00760 return sub_node;
00761 }
00762
00763 cerr << "No directory called " << DirName << endl;
00764 return 0;
00765 }
00766
00767
00768
00769 void DirectoryContainer::addToTree(DirEntry *newEntry, QString Dir)
00770 {
00771 GenericTree* Tree = TreeRoot->getChildByName(Dir);
00772 if (Tree == 0)
00773 Tree = addToTree(Dir);
00774
00775 if (newEntry)
00776 {
00777 newEntry->writeTree(Tree, speeddialTree);
00778 Tree->reorderSubnodes(2);
00779 }
00780 }
00781
00782
00783 void DirectoryContainer::setSpeedDial(DirEntry *entry)
00784 {
00785 if ((entry) && (!entry->isSpeedDial()))
00786 {
00787 entry->setSpeedDial(true);
00788
00789 entry->writeTree(0, speeddialTree);
00790 speeddialTree->reorderSubnodes(2);
00791 }
00792 }
00793
00794
00795 void DirectoryContainer::removeSpeedDial(DirEntry *entry)
00796 {
00797 if ((entry) && (entry->isSpeedDial()))
00798 {
00799 entry->setSpeedDial(false);
00800
00801
00802 speeddialTree->deleteAllChildren();
00803
00804 Directory *it;
00805 for (it=AllDirs.first(); it; it=AllDirs.next())
00806 it->writeTree(0, speeddialTree);
00807 }
00808 }
00809
00810
00811 GenericTree *DirectoryContainer::findInTree(GenericTree *Root, int at1, int atv1, int at2, int atv2)
00812 {
00813
00814 GenericTree *temp;
00815 GenericTree *Tree = Root;
00816
00817 while ((Tree) && (Tree->getAttribute(at1) != atv1) && (Tree->getAttribute(at2) != atv2))
00818 {
00819
00820 if (Tree->childCount() > 0)
00821 {
00822 Tree = Tree->getChildAt(0);
00823 continue;
00824 }
00825
00826 if (Tree == Root)
00827 return 0;
00828
00829
00830 if ((temp = Tree->nextSibling(1)) == 0)
00831 {
00832 do {
00833 Tree = Tree->getParent();
00834 if (Tree == Root)
00835 return 0;
00836
00837 } while ((temp = Tree->nextSibling(1)) == 0);
00838 Tree = temp;
00839 }
00840 Tree = temp;
00841 }
00842 return Tree;
00843 }
00844
00845 void DirectoryContainer::deleteFromTree(GenericTree *treeObject, DirEntry *entry)
00846 {
00847 QString DirName = 0;
00848 if (entry)
00849 {
00850 if (entry->isSpeedDial())
00851 removeSpeedDial(entry);
00852
00853
00854 Directory *it;
00855 for (it=AllDirs.first(); it; it=AllDirs.next())
00856 {
00857 if (it->fetchById(entry->getId()))
00858 {
00859 it->deleteEntry(entry);
00860
00861
00862
00863 GenericTree *itemDir = treeObject->getParent();
00864 itemDir->deleteAllChildren();
00865 it->writeTree(itemDir, 0);
00866 break;
00867 }
00868 }
00869 }
00870 }
00871
00872
00873 void DirectoryContainer::getRecentCalls(DirEntry *source, CallHistory &RecentCalls)
00874 {
00875 CallRecord *cr;
00876
00877 for (cr=callHistory->first(); cr; cr=callHistory->next())
00878 {
00879 if (source->urlMatches(cr->getUri()))
00880 {
00881 CallRecord *crCopy = new CallRecord(cr);
00882 RecentCalls.append(crCopy);
00883 }
00884 }
00885 }
00886
00887
00888 DirEntry *DirectoryContainer::getDirEntrybyDbId(int dbId)
00889 {
00890 DirEntry *entry = 0;
00891 Directory *it;
00892 for (it=AllDirs.first(); (it) && (entry == 0); it=AllDirs.next())
00893 entry = it->getDirEntrybyDbId(dbId);
00894 return entry;
00895 }
00896
00897 void DirectoryContainer::saveChangesinDB()
00898 {
00899 Directory *it;
00900 for (it=AllDirs.first(); it; it=AllDirs.next())
00901 it->saveChangesinDB();
00902 callHistory->saveChangesinDB();
00903 }
00904
00905
00906 DirEntry *DirectoryContainer::FindMatchingDirectoryEntry(QString url)
00907 {
00908
00909 DirEntry *entry = 0;
00910 Directory *it;
00911
00912 for (it=AllDirs.first(); (it) && (entry == 0); it=AllDirs.next())
00913 entry = it->getDirEntrybyUrl(url);
00914
00915 return entry;
00916 }
00917
00918
00919 void DirectoryContainer::PutVoicemailInTree(GenericTree *tree_to_write_to)
00920 {
00921 QString dirName = MythContext::GetConfDir() + "/MythPhone/Voicemail";
00922 QDir dir(dirName, "*.wav", QDir::Time, QDir::Files);
00923 if (!dir.exists())
00924 {
00925 cout << MythContext::GetConfDir() << "/MythPhone/Voicemail does not exist -- its meant to get created earlier so this is wrong\n";
00926 return;
00927 }
00928
00929
00930 const QFileInfoList *il = dir.entryInfoList();
00931 if (il)
00932 {
00933 QFileInfoListIterator it(*il);
00934 QFileInfo *fi;
00935 for (int i=0; (fi = it.current()) != 0; ++it, i++)
00936 {
00937 GenericTree *sub_node = tree_to_write_to->addNode(fi->baseName(), 0, true);
00938 sub_node->setAttribute(0, TA_VMAIL_ENTRY);
00939 sub_node->setAttribute(1, i);
00940 sub_node->setAttribute(2, i);
00941 }
00942 }
00943 }
00944
00945
00946 void DirectoryContainer::deleteVoicemail(QString vmailName)
00947 {
00948
00949 QString dirName = MythContext::GetConfDir() + "/MythPhone/Voicemail";
00950 QDir dir(dirName, "*.wav", QDir::Time, QDir::Files);
00951 if (!dir.exists())
00952 {
00953 cout << MythContext::GetConfDir() << "/MythPhone/Voicemail does not exist -- its meant to get created earlier so this is wrong\n";
00954 return;
00955 }
00956
00957
00958 dir.remove(vmailName + ".wav");
00959
00960
00961 voicemailTree->deleteAllChildren();
00962 PutVoicemailInTree(voicemailTree);
00963 }
00964
00965
00966
00967 void DirectoryContainer::clearAllVoicemail()
00968 {
00969
00970 QString dirName = MythContext::GetConfDir() + "/MythPhone/Voicemail";
00971 QDir dir(dirName, "*.wav", QDir::Time, QDir::Files);
00972 if (!dir.exists())
00973 {
00974 cout << MythContext::GetConfDir() << "/MythPhone/Voicemail does not exist -- its meant to get created earlier so this is wrong\n";
00975 return;
00976 }
00977
00978
00979
00980
00981 GenericTree *Node = voicemailTree->getChildAt(0);
00982 while (Node)
00983 {
00984 dir.remove(Node->getString() + ".wav");
00985
00986 Node = Node->nextSibling(1);
00987 }
00988
00989
00990 voicemailTree->deleteAllChildren();
00991 }
00992
00993
00994 QStrList DirectoryContainer::ListAllEntries(bool SpeeddialsOnly)
00995 {
00996 QStrList l;
00997 Directory *it;
00998 for (it=AllDirs.first(); it; it=AllDirs.next())
00999 {
01000 it->AddAllEntriesToList(l, SpeeddialsOnly);
01001 }
01002 return l;
01003 }
01004
01005
01006 void DirectoryContainer::ChangePresenceStatus(QString Uri, int Status, QString StatusString, bool SpeeddialsOnly)
01007 {
01008 Directory *it;
01009 for (it=AllDirs.first(); it; it=AllDirs.next())
01010 {
01011 it->ChangePresenceStatus(Uri, Status, StatusString, SpeeddialsOnly);
01012 }
01013 }
01014