qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
status.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre 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 3 of the License, or
9  (at your option) any later version.
10 
11  qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include <src/model/status.h>
21 
22 #include <QString>
23 #include <QPixmap>
24 #include <QDebug>
25 #include <QObject>
26 
27 #include <cassert>
28 
29 namespace Status
30 {
31  QString getTitle(Status status)
32  {
33  switch (status) {
34  case Status::Online:
35  return QObject::tr("online", "contact status");
36  case Status::Away:
37  return QObject::tr("away", "contact status");
38  case Status::Busy:
39  return QObject::tr("busy", "contact status");
40  case Status::Offline:
41  return QObject::tr("offline", "contact status");
42  case Status::Blocked:
43  return QObject::tr("blocked", "contact status");
45  return QObject::tr("negotitating", "contact status");
46  }
47 
48  assert(false);
49  return QStringLiteral("");
50  }
51 
52  QString getAssetSuffix(Status status)
53  {
54  switch (status) {
55  case Status::Online:
56  return "online";
57  case Status::Away:
58  return "away";
59  case Status::Busy:
60  return "busy";
61  case Status::Offline:
62  return "offline";
63  case Status::Blocked:
64  return "blocked";
66  return "negotiating";
67  }
68  assert(false);
69  return QStringLiteral("");
70  }
71 
72  QString getIconPath(Status status, bool event)
73  {
74  const QString eventSuffix = event ? QStringLiteral("_notification") : QString();
75  const QString statusSuffix = getAssetSuffix(status);
76  if (status == Status::Blocked) {
77  return ":/img/status/" + statusSuffix + ".svg";
78  } else {
79  return ":/img/status/" + statusSuffix + eventSuffix + ".svg";
80  }
81  }
82 
83  bool isOnline(Status status)
84  {
85  return status != Status::Offline
86  && status != Status::Blocked
87  // We don't want to treat a friend as online unless we know their feature set
88  && status != Status::Negotiating;
89  }
90 } // namespace Status
Status::Status::Offline
@ Offline
Status::Status::Busy
@ Busy
Status::getIconPath
QString getIconPath(Status status, bool event)
Definition: status.cpp:72
Status::Status::Online
@ Online
Status
Definition: status.cpp:29
Status::Status::Blocked
@ Blocked
Status::Status::Away
@ Away
Status::getTitle
QString getTitle(Status status)
Definition: status.cpp:31
Status::Status::Negotiating
@ Negotiating
Status::getAssetSuffix
QString getAssetSuffix(Status status)
Definition: status.cpp:52
Status::isOnline
bool isOnline(Status status)
Definition: status.cpp:83
status.h