root/trunk/qt4-gui/src/config/contactlist.cpp

Revision 6484, 13.4 kB (checked in by flynd, 3 months ago)

Changed default value to true as that is likely the behaviour most people expect.

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 "contactlist.h"
22
23#include "config.h"
24
25#include <licq_file.h>
26#include <licq_user.h>
27
28using namespace LicqQtGui;
29
30Config::ContactList* Config::ContactList::myInstance = NULL;
31
32void Config::ContactList::createInstance(QObject* parent)
33{
34  myInstance = new Config::ContactList(parent);
35}
36
37Config::ContactList::ContactList(QObject* parent)
38  : QObject(parent),
39    myLayoutHasChanged(false),
40    myListHasChanged(false),
41    myLookHasChanged(false),
42    myBlockUpdates(false)
43{
44}
45
46void Config::ContactList::loadConfiguration(CIniFile& iniFile)
47{
48  iniFile.SetSection("appearance");
49  iniFile.ReadBool("GridLines", myShowGridLines, false);
50  iniFile.ReadBool("FontStyles", myUseFontStyles, true);
51  iniFile.ReadBool("ShowHeader", myShowHeader, true);
52  iniFile.ReadBool("ShowOfflineUsers", myShowOffline, true);
53  iniFile.ReadBool("AlwaysShowONU", myAlwaysShowONU, true);
54  iniFile.ReadBool("ShowDividers", myShowDividers, true);
55  iniFile.ReadNum("SortByStatus", mySortByStatus, 1);
56  iniFile.ReadNum("SortColumn", mySortColumn, 0);
57  iniFile.ReadBool("SortColumnAscending", mySortColumnAscending, true);
58  iniFile.ReadBool("UseThreadView", myThreadView, true);
59  iniFile.ReadBool("ShowEmptyGroups", myShowEmptyGroups, true);
60  iniFile.ReadNum("TVGroupStates", myGroupStates, 0xFFFFFFFE);
61  iniFile.ReadBool("ShowExtIcons", myShowExtendedIcons, true);
62  iniFile.ReadBool("ShowPhoneIcons", myShowPhoneIcons, true);
63  iniFile.ReadBool("ShowUserIcons", myShowUserIcons, true);
64  iniFile.ReadBool("ScrollBar", myAllowScrollBar, true);
65  iniFile.ReadBool("SystemBackground", myUseSystemBackground, false);
66  iniFile.ReadBool("DragMovesUser", myDragMovesUser, true);
67
68  unsigned short flash;
69  iniFile.ReadNum("Flash", flash, FlashUrgent);
70  myFlash = static_cast<FlashMode>(flash);
71
72  unsigned short groupType;
73  iniFile.ReadNum("StartUpGroupId", myGroupId, GROUP_ALL_USERS);
74  iniFile.ReadNum("StartUpGroupType", groupType, GROUPS_SYSTEM);
75  myGroupType = static_cast<GroupType>(groupType);
76
77  // Check that the group actually exists
78  if (!gUserManager.groupExists(myGroupType, myGroupId))
79  {
80    myGroupId = GROUP_ALL_USERS;
81    myGroupType = GROUPS_SYSTEM;
82  }
83
84  iniFile.ReadNum("NumColumns", myColumnCount, 1);
85  for (unsigned short i = 0; i < myColumnCount; i++)
86  {
87    char s[32];
88    unsigned short us;
89
90    QString key = QString("Column%1.").arg(i + 1);
91    iniFile.ReadStr((key + "Title").toLatin1().data(), s, "Alias");
92    myColumnHeading[i] = QString::fromLocal8Bit(s);
93    iniFile.ReadStr((key + "Format").toLatin1().data(), s, "%a");
94    myColumnFormat[i] = QString::fromLocal8Bit(s);
95    iniFile.ReadNum((key + "Width").toLatin1().data(), myColumnWidth[i], 100);
96    iniFile.ReadNum((key + "Align").toLatin1().data(), us, 0);
97    myColumnAlignment[i] = static_cast<AlignmentMode>(us);
98  }
99
100  iniFile.ReadBool("showPopPicture", myPopupPicture, true);
101  iniFile.ReadBool("showPopAlias", myPopupAlias, false);
102  iniFile.ReadBool("showPopAuth", myPopupAuth, false);
103  iniFile.ReadBool("showPopName", myPopupName, false);
104  iniFile.ReadBool("showPopEmail", myPopupEmail, false);
105  iniFile.ReadBool("showPopPhone", myPopupPhone, true);
106  iniFile.ReadBool("showPopFax", myPopupFax, false);
107  iniFile.ReadBool("showPopCellular", myPopupCellular, true);
108  iniFile.ReadBool("showPopIP", myPopupIP, false);
109  iniFile.ReadBool("showPopLastOnelin", myPopupLastOnline, false);
110  iniFile.ReadBool("showPopOnlineSince", myPopupOnlineSince, false);
111  iniFile.ReadBool("showPopIdleTime", myPopupIdleTime, true);
112  iniFile.ReadBool("showPopLocalTime", myPopupLocalTime, false);
113  iniFile.ReadBool("showPopID", myPopupID, true);
114
115  emit listLayoutChanged();
116  emit currentListChanged();
117  emit listLookChanged();
118}
119
120void Config::ContactList::saveConfiguration(CIniFile& iniFile) const
121{
122  iniFile.SetSection("appearance");
123  iniFile.WriteBool("GridLines", myShowGridLines);
124  iniFile.WriteBool("FontStyles", myUseFontStyles);
125  iniFile.WriteBool("ShowHeader", myShowHeader);
126  iniFile.WriteBool("ShowDividers", myShowDividers);
127  iniFile.WriteNum("SortByStatus", mySortByStatus);
128  iniFile.WriteNum("SortColumn", mySortColumn);
129  iniFile.WriteBool("SortColumnAscending", mySortColumnAscending);
130  iniFile.WriteBool("ShowOfflineUsers", myShowOffline);
131  iniFile.WriteBool("AlwaysShowONU", myAlwaysShowONU);
132  iniFile.WriteBool("UseThreadView", myThreadView);
133  iniFile.WriteBool("ShowEmptyGroups", myShowEmptyGroups);
134  iniFile.WriteNum("TVGroupStates", myGroupStates);
135  iniFile.WriteBool("ShowExtIcons", myShowExtendedIcons);
136  iniFile.WriteBool("ShowPhoneIcons", myShowPhoneIcons);
137  iniFile.WriteBool("ShowUserIcons", myShowUserIcons);
138  iniFile.WriteNum("Flash", static_cast<unsigned short>(myFlash));
139  iniFile.WriteBool("ScrollBar", myAllowScrollBar);
140  iniFile.WriteBool("SystemBackground", myUseSystemBackground);
141  iniFile.WriteBool("DragMovesUser", myDragMovesUser);
142  iniFile.WriteNum("StartUpGroupId", myGroupId);
143  iniFile.WriteNum("StartUpGroupType", static_cast<unsigned short>(myGroupType));
144
145  iniFile.WriteNum("NumColumns", myColumnCount);
146  for (unsigned short i = 0; i < myColumnCount; i++)
147  {
148    QString key = QString("Column%1.").arg(i + 1);
149    iniFile.WriteStr((key + "Title").toLatin1().data(), myColumnHeading[i].toLocal8Bit().data());
150    iniFile.WriteStr((key + "Format").toLatin1().data(), myColumnFormat[i].toLocal8Bit().data());
151    iniFile.WriteNum((key + "Width").toLatin1().data(), myColumnWidth[i]);
152    iniFile.WriteNum((key + "Align").toLatin1().data(), static_cast<unsigned short>(myColumnAlignment[i]));
153  }
154
155  iniFile.WriteBool("showPopPicture", myPopupPicture);
156  iniFile.WriteBool("showPopAlias", myPopupAlias);
157  iniFile.WriteBool("showPopAuth", myPopupAuth);
158  iniFile.WriteBool("showPopName", myPopupName);
159  iniFile.WriteBool("showPopEmail", myPopupEmail);
160  iniFile.WriteBool("showPopPhone", myPopupPhone);
161  iniFile.WriteBool("showPopFax", myPopupFax);
162  iniFile.WriteBool("showPopCellular", myPopupCellular);
163  iniFile.WriteBool("showPopIP", myPopupIP);
164  iniFile.WriteBool("showPopLastOnelin", myPopupLastOnline);
165  iniFile.WriteBool("showPopOnlineSince", myPopupOnlineSince);
166  iniFile.WriteBool("showPopIdleTime", myPopupIdleTime);
167  iniFile.WriteBool("showPopLocalTime", myPopupLocalTime);
168  iniFile.WriteBool("showPopID", myPopupID);
169}
170
171void Config::ContactList::blockUpdates(bool block)
172{
173  myBlockUpdates = block;
174
175  if (block)
176    return;
177
178  if (myLayoutHasChanged)
179  {
180    myLayoutHasChanged = false;
181    emit listLayoutChanged();
182  }
183  if (myListHasChanged)
184  {
185    myListHasChanged = false;
186    emit currentListChanged();
187  }
188  if (myLookHasChanged)
189  {
190    myLookHasChanged = false;
191    emit listLookChanged();
192  }
193}
194
195void Config::ContactList::setColumnCount(int columnCount)
196{
197  if (columnCount == myColumnCount || columnCount < 0 || columnCount >= MAX_COLUMNCOUNT)
198    return;
199
200  myColumnCount = columnCount;
201
202  changeListLayout();
203}
204
205void Config::ContactList::setColumn(int column, QString heading, QString format, unsigned short width, AlignmentMode alignment)
206{
207  if (column < 0 || column >= MAX_COLUMNCOUNT)
208    return;
209
210  if (myColumnFormat[column] != format)
211  {
212    myColumnFormat[column] = format;
213    changeListLayout();
214  }
215
216  if (heading != myColumnHeading[column] ||
217      width != myColumnWidth[column] ||
218      alignment != myColumnAlignment[column])
219  {
220    myColumnHeading[column] = heading;
221    myColumnWidth[column] = width;
222    myColumnAlignment[column] = alignment;
223    changeListLook();
224  }
225}
226
227void Config::ContactList::setSortByStatus(unsigned short sortByStatus)
228{
229  if (sortByStatus == mySortByStatus)
230    return;
231
232  mySortByStatus = sortByStatus;
233
234  changeListLayout();
235}
236
237void Config::ContactList::setShowGridLines(bool showGridLines)
238{
239  if (showGridLines == myShowGridLines)
240    return;
241
242  myShowGridLines = showGridLines;
243
244  changeListLook();
245}
246
247void Config::ContactList::setUseFontStyles(bool useFontStyles)
248{
249  if (useFontStyles == myUseFontStyles)
250    return;
251
252  myUseFontStyles = useFontStyles;
253
254  changeListLook();
255}
256
257void Config::ContactList::setShowHeader(bool showHeader)
258{
259  if (showHeader == myShowHeader)
260    return;
261
262  myShowHeader = showHeader;
263
264  changeListLook();
265}
266
267void Config::ContactList::setShowExtendedIcons(bool showExtendedIcons)
268{
269  if (showExtendedIcons == myShowExtendedIcons)
270    return;
271
272  myShowExtendedIcons = showExtendedIcons;
273
274  changeListLook();
275}
276
277void Config::ContactList::setShowPhoneIcons(bool showPhoneIcons)
278{
279  if (showPhoneIcons == myShowPhoneIcons)
280    return;
281
282  myShowPhoneIcons = showPhoneIcons;
283
284  changeListLook();
285}
286
287void Config::ContactList::setShowUserIcons(bool showUserIcons)
288{
289  if (showUserIcons == myShowUserIcons)
290    return;
291
292  myShowUserIcons = showUserIcons;
293
294  changeListLook();
295}
296
297void Config::ContactList::setFlash(FlashMode flash)
298{
299  if (flash == myFlash)
300    return;
301
302  myFlash = flash;
303
304  changeListLook();
305}
306
307void Config::ContactList::setAllowScrollBar(bool allowScrollBar)
308{
309  if (allowScrollBar == myAllowScrollBar)
310    return;
311
312  myAllowScrollBar = allowScrollBar;
313
314  changeListLook();
315}
316
317void Config::ContactList::setUseSystemBackground(bool useSystemBackground)
318{
319  if (useSystemBackground == myUseSystemBackground)
320    return;
321
322  myUseSystemBackground = useSystemBackground;
323
324  changeListLook();
325}
326
327void Config::ContactList::setDragMovesUser(bool dragMovesUser)
328{
329  if (dragMovesUser == myDragMovesUser)
330    return;
331
332  myDragMovesUser = dragMovesUser;
333}
334
335void Config::ContactList::setShowDividers(bool showDividers)
336{
337  if (showDividers == myShowDividers)
338    return;
339
340  myShowDividers = showDividers;
341
342  changeCurrentList();
343}
344
345void Config::ContactList::setAlwaysShowONU(bool alwaysShowONU)
346{
347  if (alwaysShowONU == myAlwaysShowONU)
348    return;
349
350  myAlwaysShowONU = alwaysShowONU;
351
352  changeCurrentList();
353}
354
355void Config::ContactList::setShowOffline(bool showOffline)
356{
357  if (showOffline == myShowOffline)
358    return;
359
360  myShowOffline = showOffline;
361
362  changeCurrentList();
363}
364
365void Config::ContactList::setThreadView(bool threadView)
366{
367  if (threadView == myThreadView)
368    return;
369
370  myThreadView = threadView;
371
372  changeCurrentList();
373}
374
375void Config::ContactList::setShowEmptyGroups(bool showEmptyGroups)
376{
377  if (showEmptyGroups == myShowEmptyGroups)
378    return;
379
380  myShowEmptyGroups = showEmptyGroups;
381
382  changeCurrentList();
383}
384
385void Config::ContactList::setGroup(GroupType groupType, unsigned long groupId)
386{
387  if (groupType == myGroupType && groupId == myGroupId)
388    return;
389
390  myGroupType = groupType;
391  myGroupId = groupId;
392
393  changeCurrentList();
394}
395
396void Config::ContactList::setSortColumn(unsigned short column, bool ascending)
397{
398  mySortColumn = column;
399  mySortColumnAscending = ascending;
400
401  emit listSortingChanged();
402}
403
404bool Config::ContactList::groupState(unsigned short group) const
405{
406  return myGroupStates & (1 << qMin(static_cast<int>(group), 31));
407}
408
409void Config::ContactList::setGroupState(unsigned short group, bool expanded)
410{
411  if(group > 31)
412    group = 31;
413
414  if (expanded)
415    myGroupStates |= (1 << group);
416  else
417    myGroupStates &= ~(1 << group);
418
419  // Called by view when a group has changed state so don't emit any signal
420}
421
422void Config::ContactList::setPopupPicture(bool popupPicture)
423{
424  myPopupPicture = popupPicture;
425}
426
427void Config::ContactList::setPopupAlias(bool popupAlias)
428{
429  myPopupAlias = popupAlias;
430}
431
432void Config::ContactList::setPopupAuth(bool popupAuth)
433{
434  myPopupAuth = popupAuth;
435}
436
437void Config::ContactList::setPopupName(bool popupName)
438{
439  myPopupName = popupName;
440}
441
442void Config::ContactList::setPopupEmail(bool popupEmail)
443{
444  myPopupEmail = popupEmail;
445}
446
447void Config::ContactList::setPopupPhone(bool popupPhone)
448{
449  myPopupPhone = popupPhone;
450}
451
452void Config::ContactList::setPopupFax(bool popupFax)
453{
454  myPopupFax = popupFax;
455}
456
457void Config::ContactList::setPopupCellular(bool popupCellular)
458{
459  myPopupCellular = popupCellular;
460}
461
462void Config::ContactList::setPopupIP(bool popupIP)
463{
464  myPopupIP = popupIP;
465}
466
467void Config::ContactList::setPopupLastOnline(bool popupLastOnline)
468{
469  myPopupLastOnline = popupLastOnline;
470}
471
472void Config::ContactList::setPopupOnlineSince(bool popupOnlineSince)
473{
474  myPopupOnlineSince = popupOnlineSince;
475}
476
477void Config::ContactList::setPopupIdleTime(bool popupIdleTime)
478{
479  myPopupIdleTime = popupIdleTime;
480}
481
482void Config::ContactList::setPopupLocalTime(bool popupLocalTime)
483{
484  myPopupLocalTime = popupLocalTime;
485}
486
487void Config::ContactList::setPopupID(bool popupID)
488{
489  myPopupID = popupID;
490}
491
492void Config::ContactList::changeListLayout()
493{
494  if (myBlockUpdates)
495    myLayoutHasChanged = true;
496  else
497    emit listLayoutChanged();
498}
499
500void Config::ContactList::changeCurrentList()
501{
502  if (myBlockUpdates)
503    myListHasChanged = true;
504  else
505    emit currentListChanged();
506}
507
508void Config::ContactList::changeListLook()
509{
510  if (myBlockUpdates)
511    myLookHasChanged = true;
512  else
513    emit listLookChanged();
514}
Note: See TracBrowser for help on using the browser.