1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "managedefinitionsdialog.h"
37 #include <QtCore/QUrl>
38 #include <QtCore/QIODevice>
39 #include <QtCore/QXmlStreamReader>
40 #include <QtCore/QXmlStreamAttributes>
41 #include <QtCore/QFuture>
42 #include <QtCore/QFutureWatcher>
43 #include <QtCore/QtConcurrentMap>
44 #include <QtCore/QFile>
45 #include <QtCore/QFileInfo>
46 #include <QtGui/QMessageBox>
48 #include <QtCore/QDebug>
50 using namespace TextEditor;
51 using namespace Internal;
53 ManageDefinitionsDialog::ManageDefinitionsDialog(
54 const QList<HighlightDefinitionMetaData> &metaDataList,
58 m_definitionsMetaData(metaDataList),
62 ui.definitionsTable->setHorizontalHeaderLabels(
63 QStringList() << tr("Name") << tr("Installed") << tr("Available"));
64 ui.definitionsTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
66 setWindowTitle(tr("Download Definitions"));
68 populateDefinitionsWidget();
70 connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(downloadDefinitions()));
71 connect(ui.allButton, SIGNAL(clicked()), this, SLOT(selectAll()));
72 connect(ui.clearButton, SIGNAL(clicked()), this, SLOT(clearSelection()));
73 connect(ui.invertButton, SIGNAL(clicked()), this, SLOT(invertSelection()));
76 void ManageDefinitionsDialog::populateDefinitionsWidget()
78 const int size = m_definitionsMetaData.size();
79 ui.definitionsTable->setRowCount(size);
80 for (int i = 0; i < size; ++i) {
81 const HighlightDefinitionMetaData &downloadData = m_definitionsMetaData.at(i);
83 // Look for this definition in the current path specified by the user, not the one
84 // stored in the settings. So the manager should not be queried for this information.
86 QFileInfo fi(m_path + downloadData.fileName());
87 QFile definitionFile(fi.absoluteFilePath());
88 if (definitionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
89 const QSharedPointer<HighlightDefinitionMetaData> &data = Manager::parseMetadata(fi);
91 dirVersion = data->version();
94 for (int j = 0; j < 3; ++j) {
95 QTableWidgetItem *item = new QTableWidgetItem;
97 item->setText(downloadData.name());
99 item->setText(dirVersion);
100 item->setTextAlignment(Qt::AlignCenter);
102 item->setText(downloadData.version());
103 item->setTextAlignment(Qt::AlignCenter);
105 ui.definitionsTable->setItem(i, j, item);
110 void ManageDefinitionsDialog::downloadDefinitions()
112 if (Manager::instance()->isDownloadingDefinitions()) {
113 QMessageBox::information(
115 tr("Download Information"),
116 tr("There is already one download in progress. Please wait until it is finished."));
121 foreach (const QModelIndex &index, ui.definitionsTable->selectionModel()->selectedRows())
122 urls.append(m_definitionsMetaData.at(index.row()).url());
123 Manager::instance()->downloadDefinitions(urls, m_path);
127 void ManageDefinitionsDialog::selectAll()
129 ui.definitionsTable->selectAll();
130 ui.definitionsTable->setFocus();
133 void ManageDefinitionsDialog::clearSelection()
135 ui.definitionsTable->clearSelection();
138 void ManageDefinitionsDialog::invertSelection()
140 const QModelIndex &topLeft = ui.definitionsTable->model()->index(0, 0);
141 const QModelIndex &bottomRight =
142 ui.definitionsTable->model()->index(ui.definitionsTable->rowCount() - 1,
143 ui.definitionsTable->columnCount() - 1);
144 QItemSelection itemSelection(topLeft, bottomRight);
145 ui.definitionsTable->selectionModel()->select(itemSelection, QItemSelectionModel::Toggle);
146 ui.definitionsTable->setFocus();
149 void ManageDefinitionsDialog::changeEvent(QEvent *e)
151 QDialog::changeEvent(e);
153 case QEvent::LanguageChange:
154 ui.retranslateUi(this);