AbstractEventCountNotifier.hpp 2.1 KB
Newer Older
1
/*
2
 * AbstractEventCountNotifier.hpp
3
 * Copyright (C) 2017-2018  Belledonne Communications, Grenoble, France
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *  Created on: June 29, 2017
 *      Author: Ronan Abhamon
 */

23 24
#ifndef ABSTRACT_EVENT_COUNT_NOTIFIER_H_
#define ABSTRACT_EVENT_COUNT_NOTIFIER_H_
25

26 27
#include <memory>

28
#include <QHash>
29
#include <QObject>
30
#include <QPair>
31 32 33 34

// =============================================================================

namespace linphone {
35
  class ChatMessage;
36 37
}

38
class CallModel;
39 40
class ChatModel;

41
class AbstractEventCountNotifier : public QObject {
42 43 44
  Q_OBJECT;

public:
45
  AbstractEventCountNotifier (QObject *parent = Q_NULLPTR);
46

47
  void updateUnreadMessageCount ();
48

49 50 51 52 53
  int getUnreadMessageCount () const { return mUnreadMessageCount; }
  int getMissedCallCount () const {
    int t = 0;
    for (int n : mMissedCalls) t += n;
    return t;
54 55
  }

56 57
  int getEventCount () const { return mUnreadMessageCount + getMissedCallCount(); }

58
signals:
59
  void eventCountChanged (int count);
60

61
protected:
62
  virtual void notifyEventCount (int n) = 0;
63 64

private:
65 66 67
  using ConferenceId = QPair<QString, QString>;

  void internalnotifyEventCount ();
68 69 70

  void handleChatModelCreated (const std::shared_ptr<ChatModel> &chatModel);

71 72 73 74
  void handleChatModelFocused (ChatModel *chatModel);
  void handleCallMissed (CallModel *callModel);

  QHash<ConferenceId, int> mMissedCalls;
75
  int mUnreadMessageCount = 0;
76
};
77

78
#endif // ABSTRACT_EVENT_COUNT_NOTIFIER_H_