~ubuntu-branches/ubuntu/saucy/kopete/saucy-updates

« back to all changes in this revision

Viewing changes to .pc/kubuntu_no_break_api.diff/libkopete/kopetemimetypehandler.cpp

  • Committer: Package Import Robot
  • Author(s): Howard Chan, Michał Zając, Howard Chan
  • Date: 2013-06-28 18:19:57 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130628181957-oe71prbd9qv1ygop
Tags: 4:4.10.90-0ubuntu1
[ Michał Zając ]
* New upstream beta release

[ Howard Chan ]
* Delete the API patch since it's included in upstream now.
* Fix control file to make -dbg depend on main package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    kopetemimetypehandler.cpp - Kopete mime type handlers
3
 
 
4
 
    Copyright (c) 2004      by Richard Smith         <kde@metafoo.co.uk>
5
 
 
6
 
    Kopete    (c) 2004      by the Kopete developers <kopete-devel@kde.org>
7
 
 
8
 
    *************************************************************************
9
 
    *                                                                       *
10
 
    * This library is free software; you can redistribute it and/or         *
11
 
    * modify it under the terms of the GNU Lesser General Public            *
12
 
    * License as published by the Free Software Foundation; either          *
13
 
    * version 2 of the License, or (at your option) any later version.      *
14
 
    *                                                                       *
15
 
    *************************************************************************
16
 
*/
17
 
 
18
 
#include "kopetemimetypehandler.h"
19
 
#include "kopeteglobal.h"
20
 
#include "kopeteuiglobal.h"
21
 
 
22
 
#include <qwidget.h>
23
 
 
24
 
#include <kdebug.h>
25
 
#include <klocale.h>
26
 
#include <kio/netaccess.h>
27
 
#include <kmimetype.h>
28
 
#include <kmessagebox.h>
29
 
#include <kstandarddirs.h>
30
 
#include <kemoticons.h>
31
 
#include <kopeteemoticons.h>
32
 
 
33
 
namespace Kopete
34
 
{
35
 
 
36
 
namespace
37
 
{
38
 
        static QHash<QString, Kopete::MimeTypeHandler*> g_mimeHandlers;
39
 
        static QHash<QString, Kopete::MimeTypeHandler*> g_protocolHandlers;
40
 
}
41
 
 
42
 
class MimeTypeHandler::Private
43
 
{
44
 
public:
45
 
        Private( bool carf ) : canAcceptRemoteFiles( carf ) {}
46
 
        bool canAcceptRemoteFiles;
47
 
        QStringList mimeTypes;
48
 
        QStringList protocols;
49
 
};
50
 
 
51
 
MimeTypeHandler::MimeTypeHandler( bool canAcceptRemoteFiles )
52
 
 : d( new Private( canAcceptRemoteFiles ) )
53
 
{
54
 
}
55
 
 
56
 
MimeTypeHandler::~MimeTypeHandler()
57
 
{
58
 
        for( QStringList::iterator it = d->mimeTypes.begin(); it != d->mimeTypes.end(); ++it )
59
 
                g_mimeHandlers.remove( *it );
60
 
 
61
 
        for( QStringList::iterator it = d->protocols.begin(); it != d->protocols.end(); ++it )
62
 
                g_protocolHandlers.remove( *it );
63
 
 
64
 
        delete d;
65
 
}
66
 
 
67
 
bool MimeTypeHandler::registerAsMimeHandler( const QString &mimeType )
68
 
{
69
 
        if( g_mimeHandlers[ mimeType ] )
70
 
        {
71
 
                kWarning(14010) << "Warning: Two mime type handlers attempting"
72
 
                        " to handle " << mimeType << endl;
73
 
                return false;
74
 
        }
75
 
 
76
 
        g_mimeHandlers.insert( mimeType, this );
77
 
        d->mimeTypes.append( mimeType );
78
 
//      kDebug(14010) << "Mime type " << mimeType << " registered";
79
 
        return true;
80
 
}
81
 
 
82
 
bool MimeTypeHandler::registerAsProtocolHandler( const QString &protocol )
83
 
{
84
 
        if( g_protocolHandlers[ protocol ] )
85
 
        {
86
 
                kWarning(14010) << "Warning: Two protocol handlers attempting"
87
 
                        " to handle " << protocol << endl;
88
 
                return false;
89
 
        }
90
 
 
91
 
        g_protocolHandlers.insert( protocol, this );
92
 
        d->protocols.append( protocol );
93
 
        kDebug(14010) << "Mime type " << protocol << " registered";
94
 
        return true;
95
 
}
96
 
 
97
 
const QStringList MimeTypeHandler::mimeTypes() const
98
 
{
99
 
        return d->mimeTypes;
100
 
}
101
 
 
102
 
const QStringList MimeTypeHandler::protocols() const
103
 
{
104
 
        return d->protocols;
105
 
}
106
 
 
107
 
bool MimeTypeHandler::canAcceptRemoteFiles() const
108
 
{
109
 
        return d->canAcceptRemoteFiles;
110
 
}
111
 
 
112
 
bool MimeTypeHandler::dispatchURL( const KUrl &url )
113
 
{
114
 
        if( url.isEmpty() )
115
 
                return false;
116
 
 
117
 
        QString type = KMimeType::findByUrl( url )->name();
118
 
 
119
 
        MimeTypeHandler *mimeHandler = g_mimeHandlers[ type ];
120
 
 
121
 
        if( mimeHandler )
122
 
        {
123
 
                return dispatchToHandler( url, type, mimeHandler );
124
 
        }
125
 
        else
126
 
        {
127
 
                mimeHandler = g_protocolHandlers[ url.protocol() ];
128
 
 
129
 
                if( mimeHandler )
130
 
                {
131
 
                        mimeHandler->handleURL( QString(), url );
132
 
                        return true;
133
 
                }
134
 
                else
135
 
                {
136
 
                        kDebug(14010) << "No mime type handler can handle this URL: " << url.prettyUrl();
137
 
                        return false;
138
 
                }
139
 
        }
140
 
}
141
 
 
142
 
bool MimeTypeHandler::dispatchToHandler( const KUrl &url, const QString &mimeType, MimeTypeHandler *handler )
143
 
{
144
 
        if( !handler->canAcceptRemoteFiles() )
145
 
        {
146
 
                QString file;
147
 
                if( !KIO::NetAccess::download( url, file, Kopete::UI::Global::mainWidget() ) )
148
 
                {
149
 
                        QString sorryText;
150
 
                        if ( url.isLocalFile() )
151
 
                        {
152
 
                                sorryText = i18n( "Unable to find the file %1.", url.prettyUrl() );
153
 
                        }
154
 
                        else
155
 
                        {
156
 
                                sorryText = i18n( "<qt>Unable to download the requested file;<br />"
157
 
                                                  "please check that address %1 is correct.</qt>",
158
 
                                                  url.prettyUrl() );
159
 
                        }
160
 
 
161
 
                        KMessageBox::sorry( Kopete::UI::Global::mainWidget(), sorryText );
162
 
                        return false;
163
 
                }
164
 
 
165
 
                KUrl dest;
166
 
                dest.setPath( file );
167
 
 
168
 
                handler->handleURL( mimeType, dest );
169
 
 
170
 
                // for now, local-only handlers have to be synchronous
171
 
                KIO::NetAccess::removeTempFile( file );
172
 
        }
173
 
        else
174
 
        {
175
 
                handler->handleURL( mimeType, url );
176
 
        }
177
 
 
178
 
        return true;
179
 
}
180
 
 
181
 
void MimeTypeHandler::handleURL( const QString &mimeType, const KUrl &url ) const
182
 
{
183
 
        Q_UNUSED( mimeType );
184
 
        Q_UNUSED( url );
185
 
}
186
 
 
187
 
 
188
 
EmoticonMimeTypeHandler::EmoticonMimeTypeHandler()
189
 
 : MimeTypeHandler( false )
190
 
{
191
 
        registerAsMimeHandler( QString::fromLatin1("application/x-kopete-emoticons") );
192
 
        registerAsMimeHandler( QString::fromLatin1("application/x-compressed-tar") );
193
 
        registerAsMimeHandler( QString::fromLatin1("application/x-bzip-compressed-tar") );
194
 
}
195
 
 
196
 
void EmoticonMimeTypeHandler::handleURL( const QString &, const KUrl &url ) const
197
 
{
198
 
  Emoticons::self()->installTheme( url.toLocalFile() );
199
 
}
200
 
 
201
 
 
202
 
} // END namespace Kopete
203
 
 
204
 
// vim: set noet ts=4 sts=4 sw=4: