• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

krfb

invitationmanager.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 */
00009 #include "invitationmanager.h"
00010 #include "invitationmanager.moc"
00011 
00012 #include <KConfigGroup>
00013 #include <KConfig>
00014 #include <KGlobal>
00015 
00016 #include <QTimer>
00017 
00018 class InvitationManagerPrivate
00019 {
00020 public:
00021     InvitationManager instance;
00022 };
00023 
00024 K_GLOBAL_STATIC(InvitationManagerPrivate, invitationManagerPrivate)
00025 
00026 InvitationManager * InvitationManager::self() {
00027     return &invitationManagerPrivate->instance;
00028 }
00029 
00030 InvitationManager::InvitationManager()
00031 {
00032     loadInvitations();
00033 
00034     QTimer *refreshTimer = new QTimer(this);
00035     connect(refreshTimer, SIGNAL(timeout()), SLOT(loadInvitations()));
00036     refreshTimer->start(1000*60);
00037 }
00038 
00039 
00040 InvitationManager::~InvitationManager()
00041 {
00042 
00043 }
00044 
00045 void InvitationManager::invalidateOldInvitations() {
00046     int invNum = invitationList.size();
00047 
00048     while(invNum--) {
00049         if (!invitationList[invNum].isValid()) {
00050             invitationList.removeAt(invNum);
00051         }
00052     }
00053     saveInvitations();
00054 }
00055 
00056 
00057 void InvitationManager::loadInvitations()
00058 {
00059     int invNum = invitationList.size();
00060 
00061     KSharedConfigPtr conf = KGlobal::config();
00062     KConfigGroup invitationConfig(conf, "Invitations");
00063     int numInv = invitationConfig.readEntry("invitation_num",0);
00064 
00065     invitationList.clear();
00066     for (int i = 0; i < numInv; i++) {
00067         KConfigGroup ic(conf, QString("Invitation_%1").arg(i));
00068         invitationList.append(Invitation(ic));
00069     }
00070 
00071     invalidateOldInvitations();
00072     if (numInv != invNum) {
00073         emit invitationNumChanged(invitationList.size());
00074     }
00075 
00076 }
00077 
00078 Invitation InvitationManager::addInvitation()
00079 {
00080     Invitation i;
00081     invitationList.append(i);
00082     emit invitationNumChanged(invitationList.size());
00083     saveInvitations();
00084     return i;
00085 }
00086 
00087 const QList< Invitation > & InvitationManager::invitations()
00088 {
00089     return invitationList;
00090 }
00091 
00092 void InvitationManager::saveInvitations()
00093 {
00094     KSharedConfigPtr conf = KGlobal::config();
00095     KConfigGroup invitationConfig(conf, "Invitations");
00096     int invNum = invitationList.size();
00097     invitationConfig.writeEntry("invitation_num",invNum);
00098     for (int i = 0; i < invNum; i++) {
00099         KConfigGroup ic(conf, QString("Invitation_%1").arg(i));
00100         invitationList[i].save(ic);
00101     }
00102     conf->sync();
00103 }
00104 
00105 int InvitationManager::activeInvitations()
00106 {
00107     invalidateOldInvitations();
00108     return invitationList.size();
00109 }
00110 
00111 void InvitationManager::removeInvitation(const Invitation & inv)
00112 {
00113     invitationList.removeAll(inv);
00114     saveInvitations();
00115     emit invitationNumChanged(invitationList.size());
00116 }
00117 
00118 void InvitationManager::removeAllInvitations()
00119 {
00120     invitationList.clear();
00121     saveInvitations();
00122     emit invitationNumChanged(invitationList.size());
00123 }

krfb

Skip menu "krfb"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal