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

krdc

  • sources
  • kde-4.12
  • kdenetwork
  • krdc
connectiondelegate.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Tony Murray <murraytony@gmail.com>
4 **
5 ** This file is part of KDE.
6 **
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
21 **
22 ****************************************************************************/
23 
24 #include "connectiondelegate.h"
25 #include "remotedesktopsmodel.h"
26 
27 #include <KDateTime>
28 #include <KDebug>
29 #include <KIcon>
30 #include <KIconLoader>
31 #include <KLocale>
32 
33 ConnectionDelegate::ConnectionDelegate(QObject *parent) :
34  QStyledItemDelegate(parent)
35 {
36 }
37 
38 QString ConnectionDelegate::displayText(const QVariant &value, const QLocale& locale) const
39 {
40  if (value.type() == QVariant::DateTime) {
41  KDateTime lastConnected = KDateTime(value.toDateTime());
42  KDateTime currentTime = KDateTime::currentUtcDateTime();
43 
44  int daysAgo = lastConnected.daysTo(currentTime);
45  if (daysAgo <= 1 && lastConnected.secsTo(currentTime) < 86400) {
46  int minutesAgo = lastConnected.secsTo(currentTime) / 60;
47  int hoursAgo = minutesAgo / 60;
48  if (hoursAgo < 1) {
49  if (minutesAgo < 1)
50  return i18n("Less than a minute ago");
51  return i18np("A minute ago", "%1 minutes ago", minutesAgo);
52  } else {
53  return i18np("An hour ago", "%1 hours ago", hoursAgo);
54  }
55  } else { // 1 day or more
56  if (daysAgo < 30)
57  return i18np("Yesterday", "%1 days ago", daysAgo);
58  if (daysAgo < 365)
59  return i18np("Over a month ago", "%1 months ago", daysAgo / 30);
60  return i18np("A year ago", "%1 years ago", daysAgo / 365);
61  }
62 
63  }
64  // These aren't the strings you're looking for, move along.
65  return QStyledItemDelegate::displayText(value, locale);
66 }
67 
68 void ConnectionDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
69 {
70  if (index.column() == RemoteDesktopsModel::Favorite) {
71  QVariant value = index.data(Qt::CheckStateRole);
72  if (value.isValid()) {
73  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
74  KIcon favIcon = KIcon("bookmarks");
75  KIcon::Mode mode = (checkState == Qt::Checked) ? KIcon::Active : KIcon::Disabled;
76  favIcon.paint(painter, option.rect, option.decorationAlignment, mode);
77 
78  }
79  } else {
80  QStyledItemDelegate::paint(painter, option, index);
81  }
82 }
83 
84 QSize ConnectionDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
85 {
86  if (index.column() == RemoteDesktopsModel::Favorite)
87  return QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
88  return QStyledItemDelegate::sizeHint(option, index);
89 }
ConnectionDelegate::ConnectionDelegate
ConnectionDelegate(QObject *parent=0)
Definition: connectiondelegate.cpp:33
QObject
RemoteDesktopsModel::Favorite
Definition: remotedesktopsmodel.h:67
QStyledItemDelegate
ConnectionDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: connectiondelegate.cpp:68
remotedesktopsmodel.h
ConnectionDelegate::displayText
QString displayText(const QVariant &value, const QLocale &locale) const
Definition: connectiondelegate.cpp:38
ConnectionDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: connectiondelegate.cpp:84
connectiondelegate.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krdc

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal