~qutim/qtdocktile/ubuntu

« back to all changes in this revision

Viewing changes to src/plugins/windows/temporaryicon.cpp

  • Committer: Vsevolod Velichko
  • Date: 2012-09-02 15:33:32 UTC
  • Revision ID: torkvema@gmail.com-20120902153332-1ujmwninamqzufd5
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *  temporaryicon.cpp
 
3
 *
 
4
 *  Copyright (c) 2011 by Sidorov Aleksey <gorthauer87@ya.ru>
 
5
 *
 
6
 ***************************************************************************
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 3 of the License, or (at your option) any later version.
 
12
 
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 
 
18
 * You should have received a copy of the GNU Lesser General
 
19
 * Public License along with this library; if not, write to the
 
20
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
21
 * Boston, MA 02110-1301 USA
 
22
 *
 
23
*****************************************************************************/
 
24
 
 
25
#include "temporaryicon.h"
 
26
#include <QFile>
 
27
#include <QImage>
 
28
#include <QApplication>
 
29
#include <QStyle>
 
30
#include <QUuid>
 
31
#include <QDesktopServices>
 
32
 
 
33
TemporaryIcon::TemporaryIcon(const QIcon &icon)
 
34
{
 
35
        int size = qApp->style()->pixelMetric(QStyle::PM_ListViewIconSize);
 
36
        m_iconSize = QSize(size, size);
 
37
        QImage image = icon.pixmap(m_iconSize).toImage();
 
38
        if (!image.isNull()) {
 
39
                QString name = QUuid::createUuid().toString();
 
40
                QString path = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
 
41
                m_filePath = path + QLatin1String("/") + name + QLatin1String(".ico");
 
42
                image.save(m_filePath, "ico");
 
43
        }
 
44
}
 
45
 
 
46
TemporaryIcon::~TemporaryIcon()
 
47
{
 
48
        if (!m_filePath.isNull())
 
49
                QFile::remove(m_filePath);
 
50
}
 
51
 
 
52
QString TemporaryIcon::filePath() const
 
53
{
 
54
        return m_filePath;
 
55
}