root/trunk/qt4-gui/src/dockicons/dockicon.cpp

Revision 6466, 4.1 kB (checked in by flynd, 4 months ago)

Use const pointer for owner objects that are fetched only for read access.

Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of Licq, an instant messaging client for UNIX.
4 * Copyright (C) 2007 Licq developers
5 *
6 * Licq is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Licq is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Licq; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21#include "dockicon.h"
22
23#include "config.h"
24
25#include <licq_user.h>
26
27#include "config/general.h"
28#include "config/iconmanager.h"
29
30#include "helpers/licqstrings.h"
31
32#include "dockiconwidget.h"
33
34using namespace LicqQtGui;
35/* TRANSLATOR LicqQtGui::DockIcon */
36
37DockIcon::DockIcon()
38  : QObject(),
39    myIcon(NULL),
40    myNewMsg(0),
41    mySysMsg(0),
42    myStatus(0),
43    myInvisible(false)
44{
45  // Get icon set updates
46  connect(IconManager::instance(), SIGNAL(statusIconsChanged()), SLOT(updateStatusIcon()));
47  connect(IconManager::instance(), SIGNAL(generalIconsChanged()), SLOT(updateEventIcon()));
48
49  // Get configuration updates
50  connect(Config::General::instance(), SIGNAL(dockChanged()), SLOT(updateConfig()));
51
52  unsigned short sysMsg = 0;
53
54  FOR_EACH_OWNER_START(LOCK_R)
55  {
56    sysMsg += pOwner->NewMessages();
57  }
58  FOR_EACH_OWNER_END
59
60  unsigned short newMsg = ICQUser::getNumUserEvents() - sysMsg;
61
62  updateIconMessages(newMsg, sysMsg);
63  updateIconStatus();
64}
65
66DockIcon::~DockIcon()
67{
68  delete myIcon;
69}
70
71void DockIcon::updateIconStatus()
72{
73  // First check for ICQ/AIM owner presence
74  const ICQOwner* o = gUserManager.FetchOwner(LICQ_PPID, LOCK_R);
75
76  // Take any existent one otherwise
77  if (o == NULL && gUserManager.NumOwners() != 0)
78  {
79    const OwnerList* ol = gUserManager.LockOwnerList(LOCK_R);
80    o = ol->front();
81    o->Lock(LOCK_R);
82    gUserManager.UnlockOwnerList();
83  }
84
85  if (o != NULL)
86  {
87    myId = o->IdString();
88    myPpid = o->PPID();
89    myFullStatus = o->StatusFull();
90    myStatus = o->Status();
91    myInvisible = o->StatusInvisible();
92    gUserManager.DropOwner(o);
93  }
94  else
95  {
96    // We got no owner, this could be normal if this is first run,
97    // just show status as offline until user has created the first account
98    myId = "0";
99    myPpid = LICQ_PPID;
100    myFullStatus = ICQ_STATUS_OFFLINE;
101    myStatus = ICQ_STATUS_OFFLINE;
102    myInvisible = false;
103  }
104
105  updateToolTip();
106  updateStatusIcon();
107}
108
109void DockIcon::updateStatusIcon()
110{
111  myStatusIcon = const_cast<QPixmap*>
112    (&IconManager::instance()->iconForStatus(myFullStatus, myId, myPpid));
113}
114
115void DockIcon::updateIconMessages(int newMsg, int sysMsg)
116{
117  myNewMsg = newMsg;
118  mySysMsg = sysMsg;
119
120  updateToolTip();
121  updateEventIcon();
122}
123
124void DockIcon::updateEventIcon()
125{
126  if (mySysMsg > 0)
127    myEventIcon = const_cast<QPixmap*>
128      (&IconManager::instance()->getIcon(IconManager::ReqAuthorizeMessageIcon));
129  else if (myNewMsg > 0)
130    myEventIcon = const_cast<QPixmap*>
131      (&IconManager::instance()->getIcon(IconManager::StandardMessageIcon));
132  else
133    myEventIcon = NULL;
134}
135
136void DockIcon::updateToolTip()
137{
138  QString s = QString("<nobr>%1</nobr>")
139      .arg(LicqStrings::getStatus(myStatus, myInvisible));
140
141  if (mySysMsg)
142    s += "<br><b>" + tr("%1 system messages").arg(mySysMsg) + "</b>";
143
144  if (myNewMsg > 1)
145    s += "<br>" + tr("%1 msgs").arg(myNewMsg);
146  else if (myNewMsg)
147    s += "<br>" + tr("1 msg");
148
149  s += tr("<br>Left click - Show main window"
150          "<br>Middle click - Show next message"
151          "<br>Right click - System menu");
152
153  if (myIcon != NULL)
154    myIcon->setToolTip(s);
155  else
156    emit newToolTip(s);
157}
158
159void DockIcon::relayDockIconSignals()
160{
161  if (myIcon == NULL)
162    return;
163
164  connect(myIcon, SIGNAL(clicked()), SIGNAL(clicked()));
165  connect(myIcon, SIGNAL(middleClicked()), SIGNAL(middleClicked()));
166}
Note: See TracBrowser for help on using the browser.