~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to plugins/urlpicpreview/linkpreview.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    linkpreview.cpp
 
3
 
 
4
    Copyright (c) 2005      by Heiko Schaefer        <heiko@rangun.de>
 
5
 
 
6
    Kopete    (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
 
7
 
 
8
    **************************************************************************
 
9
    *                                                                        *
 
10
    * This program is free software; you can redistribute it and/or modify   *
 
11
    * it under the terms of the GNU General Public License as published by   *
 
12
    * the Free Software Foundation; version 2, or (at your option) version 3 *
 
13
    * of the License.                                                        *
 
14
    *                                                                        *
 
15
    **************************************************************************
 
16
*/
 
17
 
 
18
//Qt
 
19
#include <qpainter.h>
 
20
 
 
21
//KDE
 
22
#include <kapplication.h>
 
23
#include <khtml_part.h>
 
24
#include <khtmlview.h>
 
25
#include <kdebug.h>
 
26
 
 
27
// Kopete
 
28
#include "urlpicpreviewplugin.h"
 
29
#include "linkpreview.h"
 
30
 
 
31
LinkPreview * LinkPreview::m_self = NULL;
 
32
 
 
33
LinkPreview::LinkPreview() : m_pic(1280, 1024), m_khtml(NULL), m_URLLoading(false) {
 
34
 
 
35
    kDebug(14314);
 
36
 
 
37
    m_khtml = new KHTMLPart();
 
38
 
 
39
    m_khtml->setJScriptEnabled(false);
 
40
    m_khtml->setJavaEnabled(false);
 
41
    m_khtml->setMetaRefreshEnabled(false);
 
42
    m_khtml->setPluginsEnabled(false);
 
43
 
 
44
    m_khtml->setStatusMessagesEnabled(false);
 
45
    m_khtml->setProgressInfoEnabled(true);
 
46
}
 
47
 
 
48
LinkPreview::~LinkPreview() {
 
49
    delete m_khtml;
 
50
 
 
51
    kDebug(14314);
 
52
}
 
53
 
 
54
LinkPreview * LinkPreview::self(const URLPicPreviewPlugin * plugin) {
 
55
    if(!m_self) {
 
56
        m_self = new LinkPreview();
 
57
        connect(plugin, SIGNAL(abortAllOperations()), m_self, SLOT(completed()));
 
58
    }
 
59
 
 
60
    return m_self;
 
61
}
 
62
 
 
63
/*!
 
64
    \fn LinkPreview::getPreviewPic(const KUrl& url)
 
65
 */
 
66
QPixmap LinkPreview::getPreviewPic(const KUrl& url) {
 
67
    QPainter painter(&m_pic);
 
68
 
 
69
    m_pic.fill();
 
70
    m_URLLoading = true;
 
71
 
 
72
    connect(m_khtml, SIGNAL(completed()), this, SLOT(completed()));
 
73
    connect(m_khtml, SIGNAL(canceled(QString)), this, SLOT(completed()));
 
74
 
 
75
    if(m_khtml->openUrl(url)) {
 
76
        kDebug(14314) << "Creating preview of " << url;
 
77
        m_khtml->view()->resize(1280, 1024);
 
78
        m_khtml->stopAnimations();
 
79
        m_khtml->paint(&painter, QRect(0, 0, 1280, 1024));
 
80
 
 
81
        while(m_URLLoading) {
 
82
            kapp->processEvents();
 
83
        }
 
84
    }
 
85
 
 
86
    disconnect(this, SLOT(completed()));
 
87
 
 
88
    return m_pic;
 
89
}
 
90
 
 
91
/*!
 
92
    \fn LinkPreview::completed()
 
93
 */
 
94
void LinkPreview::completed() {
 
95
    m_URLLoading = false;
 
96
}
 
97
 
 
98
#include "linkpreview.moc"