blob: f304b31d6dd2a77941ec072125ed59b8bdcfa2af [file] [log] [blame]
Edric Milaret4bba46d2015-04-29 16:33:38 -04001/***************************************************************************
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04002 * Copyright (C) 2015-2018 by Savoir-faire Linux *
Edric Milaret4bba46d2015-04-29 16:33:38 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04004 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
Edric Milaret4bba46d2015-04-29 16:33:38 -04005 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 **************************************************************************/
19
Edric Milaret5f316da2015-09-28 11:57:42 -040020#pragma once
Edric Milaret4bba46d2015-04-29 16:33:38 -040021
Edric Milaretb37aa1f2015-07-09 16:39:04 -040022//Needed for OS detection
23#include <QtGlobal>
24
Edric Milaret36587362016-02-04 12:30:52 -050025#ifdef Q_OS_WIN
Edric Milaret4bba46d2015-04-29 16:33:38 -040026#include <windows.h>
Andreas Traczyke0a60b52018-07-10 18:16:15 -040027#include <ciso646>
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040028#undef OUT
29#undef IN
30#undef ERROR
Edric Milaretb37aa1f2015-07-09 16:39:04 -040031#else //LINUX
32#define LPCWSTR char*
33#endif
Edric Milaret4bba46d2015-04-29 16:33:38 -040034
35#include <string>
Edric Milaret031c3052015-04-29 18:14:18 -040036#include <QString>
Edric Milaret25236d92016-03-28 09:40:58 -040037#include <QImage>
Olivier SOLDANOc1ca2df2017-09-06 16:01:46 -040038#include <QStackedWidget>
Edric Milaret4bba46d2015-04-29 16:33:38 -040039
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040040#include "api/conversationmodel.h"
41#include "api/account.h"
42#include "api/contactmodel.h"
43#include "api/contact.h"
44
Olivier SOLDANOc1ca2df2017-09-06 16:01:46 -040045namespace Utils
Edric Milaret4bba46d2015-04-29 16:33:38 -040046{
Olivier SOLDANOc1ca2df2017-09-06 16:01:46 -040047 constexpr int animDuration_ = 200; // animation duration for sliding page in ms
48
49 bool CreateStartupLink();
50 void DeleteStartupLink();
51 bool CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszPathLink);
52 bool CheckStartupLink();
53 QString GetRingtonePath();
54 QString GenGUID();
55 QString GetISODate();
56 QString GetCurrentUserName();
57 void InvokeMailto(const QString& subject, const QString& body, const QString& attachement = QString());
58 QImage getCirclePhoto(const QImage original, int sizePhoto);
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040059 void setStackWidget(QStackedWidget *stack, QWidget *widget);
60 void showSystemNotification(QWidget* widget, const QString& message, long delay = 5000);
Edric Milaret4bba46d2015-04-29 16:33:38 -040061
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040062 std::string bestIdForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model);
63 std::string bestIdForAccount(const lrc::api::account::Info & account);
64 std::string bestNameForAccount(const lrc::api::account::Info & account);
65 std::string bestIdForContact(const lrc::api::contact::Info & contact);
66 std::string bestNameForContact(const lrc::api::contact::Info & contact);
67 std::string bestNameForConversation(const lrc::api::conversation::Info & conv, const lrc::api::ConversationModel & model);
68 lrc::api::profile::Type profileType(const lrc::api::conversation::Info & conv, const lrc::api::ConversationModel & model);
69 std::string formatTimeString(const std::time_t& timestamp);
70 lrc::api::ConversationModel::ConversationQueue::const_iterator getConversationFromUid(const std::string& uid, const lrc::api::ConversationModel& model);
71 lrc::api::ConversationModel::ConversationQueue::const_iterator getConversationFromUri(const std::string& uri, const lrc::api::ConversationModel& model);
72 bool isInteractionGenerated(const lrc::api::interaction::Type& interaction);
73 bool isContactValid(const std::string& contactUid, const lrc::api::ConversationModel& model);
74 QImage conversationPhoto(const std::string& convUid, const lrc::api::account::Info& accountInfo);
75
76 // helpers
77 template<typename E>
78 constexpr inline typename std::enable_if< std::is_enum<E>::value,
79 typename std::underlying_type<E>::type
80 >::type
81 toUnderlyingValue(E e) noexcept
82 {
83 return static_cast<typename std::underlying_type<E>::type >(e);
84 }
85
86 template<typename E, typename T>
87 constexpr inline typename std::enable_if< std::is_enum<E>::value && std::is_integral<T>::value,
88 E
89 >::type
90 toEnum(T value) noexcept
91 {
92 return static_cast<E>(value);
93 }
94
95 template<typename T>
96 ptrdiff_t
97 indexInVector(const std::vector<T>& vec, const T& item)
98 {
99 auto it = std::find(vec.begin(), vec.end(), item);
100 if (it == vec.end()) {
101 return -1;
102 }
103 return std::distance(vec.begin(), it);
104 }
105}