OSDN Git Service

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