summaryrefslogtreecommitdiffstats
path: root/ui/qt/voip_calls_dialog.h
blob: 542fab9ddabbe09b530850e5809f82c663a753a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/** @file
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef VOIP_CALLS_DIALOG_H
#define VOIP_CALLS_DIALOG_H

#include <config.h>

#include <mutex>

#include "cfile.h"

#include "ui/voip_calls.h"
#include "ui/rtp_stream.h"
#include "ui/rtp_stream_id.h"

#include <ui/qt/models/voip_calls_info_model.h>
#include <ui/qt/models/cache_proxy_model.h>
#include "ui/rtp_stream_id.h"
#include "wireshark_dialog.h"

#include <QMenu>
#include <QAbstractButton>
#include <QPushButton>
#include <QToolButton>

class SequenceInfo;

namespace Ui {
class VoipCallsDialog;
}

// Singleton by https://refactoring.guru/design-patterns/singleton/cpp/example#example-1
class VoipCallsDialog : public WiresharkDialog
{
    Q_OBJECT

public:
    /**
     * Returns singleton
     */
    static VoipCallsDialog *openVoipCallsDialogVoip(QWidget &parent, CaptureFile &cf, QObject *packet_list);
    static VoipCallsDialog *openVoipCallsDialogSip(QWidget &parent, CaptureFile &cf, QObject *packet_list);

    /**
     * Should not be clonnable and assignable
     */
    VoipCallsDialog(VoipCallsDialog &other) = delete;
    void operator=(const VoipCallsDialog &) = delete;

signals:
    void updateFilter(QString filter, bool force = false);
    void captureFileChanged(capture_file *cf);
    void goToPacket(int packet_num);
    void rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *> stream_ids);
    void rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *> stream_ids);
    void rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *> stream_ids);
    void rtpStreamsDialogSelectRtpStreams(QVector<rtpstream_id_t *> stream_ids);
    void rtpStreamsDialogDeselectRtpStreams(QVector<rtpstream_id_t *> stream_ids);

public slots:
    void displayFilterSuccess(bool success);
    void rtpPlayerReplace();
    void rtpPlayerAdd();
    void rtpPlayerRemove();

protected:
    explicit VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flows = false);
    ~VoipCallsDialog();

    void contextMenuEvent(QContextMenuEvent *event);
    virtual void removeTapListeners();
    void captureFileClosing();
    void captureFileClosed();
    bool eventFilter(QObject *obj, QEvent *event);

protected slots:
    void changeEvent(QEvent* event);

private:
    // We have two singletones - one for all protocols, one for sip protocol
    static VoipCallsDialog *pinstance_voip_;
    static VoipCallsDialog *pinstance_sip_;
    bool all_flows_;
    static std::mutex init_mutex_;

    Ui::VoipCallsDialog *ui;
    VoipCallsInfoModel *call_infos_model_;
    CacheProxyModel *cache_model_;
    QSortFilterProxyModel *sorted_model_;

    QWidget &parent_;
    voip_calls_tapinfo_t tapinfo_;
    SequenceInfo *sequence_info_;
    QPushButton *prepare_button_;
    QPushButton *sequence_button_;
    QToolButton *player_button_;
    QPushButton *copy_button_;
    bool voip_calls_tap_listeners_removed_;
    GQueue* shown_callsinfos_; /* queue with all shown calls (voip_calls_info_t) */

    // Tap callbacks
    static void tapReset(void *tapinfo_ptr);
    static tap_packet_status tapPacket(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *, const void *data, tap_flags_t flags);
    static void tapDraw(void *tapinfo_ptr);
    static int compareCallNums(const void *a, const void *b);

    void updateCalls();
    void prepareFilter();
    void showSequence();
    void showPlayer();
    void removeAllCalls();
    void invertSelection();

    QList<QVariant> streamRowData(int row) const;
    QVector<rtpstream_id_t *>getSelectedRtpIds();

private slots:
    void selectAll();
    void selectNone();
    void copyAsCSV();
    void copyAsYAML();
    void switchTimeOfDay();
    void on_callTreeView_activated(const QModelIndex &index);
    void on_buttonBox_clicked(QAbstractButton *button);
    void on_buttonBox_helpRequested();
    void updateWidgets();
    void captureEvent(CaptureEvent e);
    void displayFilterCheckBoxToggled(bool checked);
    void on_actionSelectAll_triggered();
    void on_actionSelectInvert_triggered();
    void on_actionSelectNone_triggered();
    void on_actionSelectRtpStreams_triggered();
    void on_actionDeselectRtpStreams_triggered();
};

#endif // VOIP_CALLS_DIALOG_H