1 /*
2     kopetehistorydialog.h - Kopete History Dialog
3 
4     Copyright (c) 2002 by  Richard Stellingwerff <remenic@linuxfromscratch.org>
5     Copyright (c) 2004 by  Stefan Gehn <metz AT gehn.net>
6 
7     Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
8 
9     *************************************************************************
10     *                                                                       *
11     * This program is free software; you can redistribute it and/or modify  *
12     * it under the terms of the GNU General Public License as published by  *
13     * the Free Software Foundation; either version 2 of the License, or     *
14     * (at your option) any later version.                                   *
15     *                                                                       *
16     *************************************************************************
17 */
18 
19 #ifndef HISTORYDIALOG_H
20 #define HISTORYDIALOG_H
21 
22 #include <QList>
23 
24 #include <QDialog>
25 #include <QUrl>
26 #include <QDate>
27 
28 #include "kopetemessage.h"
29 
30 class QTreeWidgetItem;
31 
32 class QAction;
33 class KHTMLView;
34 class KHTMLPart;
35 namespace KParts {
36 class BrowserArguments;
37 class OpenUrlArguments;
38 class Part;
39 }
40 
41 namespace Kopete {
42 class MetaContact;
43 }
44 namespace Kopete {
45 class Contact;
46 }
47 namespace Kopete {
48 class XSLT;
49 }
50 
51 namespace Ui {
52 class HistoryViewer;
53 }
54 
55 class DMPair
56 {
57 public:
DMPair()58     DMPair()
59     {
60         md = QDate(0, 0, 0);
61         mc = 0;
62     }
63 
DMPair(QDate d,Kopete::MetaContact * c)64     DMPair(QDate d, Kopete::MetaContact *c)
65     {
66         md = d;
67         mc = c;
68     }
69 
date()70     QDate date() const
71     {
72         return md;
73     }
74 
metaContact()75     Kopete::MetaContact *metaContact() const
76     {
77         return mc;
78     }
79 
80     bool operator==(const DMPair p1) const
81     {
82         return p1.date() == this->date() && p1.metaContact() == this->metaContact();
83     }
84 
85 private:
86     QDate md;
87     Kopete::MetaContact *mc;
88 };
89 
90 /**
91  * @author Richard Stellingwerff <remenic@linuxfromscratch.org>
92  * @author Stefan Gehn <metz AT gehn.net>
93  */
94 class HistoryDialog : public QDialog
95 {
96     Q_OBJECT
97 
98 public:
99     explicit HistoryDialog(Kopete::MetaContact *mc, QWidget *parent = nullptr);
100     ~HistoryDialog();
101 
102     /**
103      * Calls init(Kopete::Contact *c) for each subcontact of the metacontact
104      */
105 
106 signals:
107     void closing();
108 
109 private slots:
110     void slotOpenURLRequest(const QUrl &url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &);
111 
112     // Called when a date is selected in the treeview
113     void dateSelected(QTreeWidgetItem *);
114 
115     void slotSearch();
116     void searchFinished();
117 
118     void slotSearchTextChanged(const QString &txt);     // To enable/disable search button
119     void slotContactChanged(int index);
120     void slotFilterChanged(int index);
121 
122     void init();
123     void slotLoadDays();
124 
125     void slotRightClick(const QString &url, const QPoint &point);
126     void slotCopy();
127     void slotCopyURL();
128 
129     void slotImportHistory();
130 
131 private:
132     enum Disabled {
133         Prev = 1, Next = 2
134     };
135     void refreshEnabled(/*Disabled*/ uint disabled);
136 
137     void initProgressBar(const QString &text, int nbSteps);
138     void doneProgressBar();
139     void init(Kopete::MetaContact *mc);
140     void init(Kopete::Contact *c);
141 
142     /**
143      * Show the messages in the HTML View
144      */
145     void setMessages(QList<Kopete::Message> m);
146 
147     void treeWidgetHideElements(bool s);
148 
149     QString highlight(const QString &htmlText, const QString &highlight) const;
150     QString escapeXMLText(const QString &text) const;
151 
152     /**
153      * We show history dialog to look at the log for a metacontact. Here is this metacontact.
154      */
155     Kopete::MetaContact *mMetaContact;
156 
157     QList<Kopete::MetaContact *> mMetaContactList;
158 
159     // History View
160     KHTMLView *mHtmlView;
161     KHTMLPart *mHtmlPart;
162     Ui::HistoryViewer *mMainWidget;
163     Kopete::XSLT *mXsltParser;
164 
165     struct Init
166     {
167         QList<DMPair> dateMCList;     // mc for MetaContact
168     } mInit;
169 
170     bool mSearching;
171 
172     QAction *mCopyAct;
173     QAction *mCopyURLAct;
174     QString mURL;
175 };
176 
177 #endif
178