OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / welcome / communitywelcomepagewidget.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "communitywelcomepagewidget.h"
34 #include "ui_communitywelcomepagewidget.h"
35
36 #include <coreplugin/rssfetcher.h>
37
38 #include <QtCore/QMap>
39 #include <QtCore/QUrl>
40 #include <QtGui/QDesktopServices>
41 #include <QtGui/QTreeWidgetItem>
42
43 struct Site {
44     const char *description;
45     const char *url;
46 };
47
48 static const Site supportSites[] = {
49     { QT_TRANSLATE_NOOP("Welcome::Internal::CommunityWelcomePageWidget",
50                         "<b>Forum Nokia</b><br /><font color='gray'>Mobile application support</font>"),
51       "http://www.forum.nokia.com/Support/"},
52     { QT_TRANSLATE_NOOP("Welcome::Internal::CommunityWelcomePageWidget",
53                         "<b>Qt LGPL Support</b><br /><font color='gray'>Buy commercial Qt support</font>"),
54       "http://shop.qt.nokia.com/en/support.html"},
55     { QT_TRANSLATE_NOOP("Welcome::Internal::CommunityWelcomePageWidget",
56                         "<b>Qt DevNet</b><br /><font color='gray'>Qt Developer Resources</font>"),
57       "http://developer.qt.nokia.com" }
58 };
59
60 static const Site sites[] = {
61     { QT_TRANSLATE_NOOP("Welcome::Internal::CommunityWelcomePageWidget",
62                         "<b>Qt Home</b><br /><font color='gray'>Qt by Nokia on the web</font>"),
63       "http://qt.nokia.com" },
64     { QT_TRANSLATE_NOOP("Welcome::Internal::CommunityWelcomePageWidget",
65                         "<b>Qt Git Hosting</b><br /><font color='gray'>Participate in Qt development</font>"),
66       "http://qt.gitorious.org"},
67     { QT_TRANSLATE_NOOP("Welcome::Internal::CommunityWelcomePageWidget",
68                         "<b>Qt Apps</b><br /><font color='gray'>Find free Qt-based apps</font>"),
69       "http://www.qt-apps.org"}
70 };
71
72 namespace Welcome {
73 namespace Internal {
74
75 static inline void populateWelcomeTreeWidget(const Site *sites, int count, Utils::WelcomeModeTreeWidget *wt)
76 {
77     for (int s = 0; s < count; s++) {
78         const QString description = CommunityWelcomePageWidget::tr(sites[s].description);
79         const QString url = QLatin1String(sites[s].url);
80         wt->addItem(description, url, url);
81     }
82 }
83
84 CommunityWelcomePageWidget::CommunityWelcomePageWidget(QWidget *parent) :
85     QWidget(parent),
86     m_rssFetcher(new Core::RssFetcher(7)),
87     ui(new Ui::CommunityWelcomePageWidget)
88 {
89     ui->setupUi(this);
90
91     connect(ui->newsTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
92     connect(ui->miscSitesTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
93     connect(ui->supportSitesTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
94
95     connect(m_rssFetcher, SIGNAL(newsItemReady(QString, QString, QString)),
96             ui->newsTreeWidget, SLOT(addNewsItem(QString, QString, QString)), Qt::QueuedConnection);
97     connect(this, SIGNAL(startRssFetching(QUrl)), m_rssFetcher, SLOT(fetch(QUrl)), Qt::QueuedConnection);
98
99     m_rssFetcher->start(QThread::LowestPriority);
100     //: Add localized feed here only if one exists
101     emit startRssFetching(QUrl(tr("http://labs.trolltech.com/blogs/feed")));
102
103     populateWelcomeTreeWidget(supportSites, sizeof(supportSites)/sizeof(Site), ui->supportSitesTreeWidget);
104     populateWelcomeTreeWidget(sites, sizeof(sites)/sizeof(Site), ui->miscSitesTreeWidget);
105 }
106
107 CommunityWelcomePageWidget::~CommunityWelcomePageWidget()
108 {
109     m_rssFetcher->exit();
110     m_rssFetcher->wait();
111     delete m_rssFetcher;
112     delete ui;
113 }
114
115 void CommunityWelcomePageWidget::slotUrlClicked(const QString &data)
116 {
117     QDesktopServices::openUrl(QUrl(data));
118 }
119
120 } // namespace Internal
121 } // namespace Welcome