Changeset View
Changeset View
Standalone View
Standalone View
src/dialogs/katedialogs.cpp
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | |||||
89 | #include <QSlider> | 89 | #include <QSlider> | ||
90 | #include <QSpinBox> | 90 | #include <QSpinBox> | ||
91 | #include <QTabBar> | 91 | #include <QTabBar> | ||
92 | #include <QTabWidget> | 92 | #include <QTabWidget> | ||
93 | #include <QToolButton> | 93 | #include <QToolButton> | ||
94 | #include <QWhatsThis> | 94 | #include <QWhatsThis> | ||
95 | #include <QDomDocument> | 95 | #include <QDomDocument> | ||
96 | 96 | | |||
97 | // trailing slash is important | | |||
98 | #define HLDOWNLOADPATH QStringLiteral("http://kate.kde.org/syntax/") | | |||
99 | | ||||
100 | //END | 97 | //END | ||
101 | 98 | | |||
102 | //BEGIN KateIndentConfigTab | 99 | //BEGIN KateIndentConfigTab | ||
103 | KateIndentConfigTab::KateIndentConfigTab(QWidget *parent) | 100 | KateIndentConfigTab::KateIndentConfigTab(QWidget *parent) | ||
104 | : KateConfigPage(parent) | 101 | : KateConfigPage(parent) | ||
105 | { | 102 | { | ||
106 | // This will let us have more separation between this page and | 103 | // This will let us have more separation between this page and | ||
107 | // the QTabWidget edge (ereslibre) | 104 | // the QTabWidget edge (ereslibre) | ||
▲ Show 20 Lines • Show All 943 Lines • ▼ Show 20 Line(s) | |||||
1051 | 1048 | | |||
1052 | QIcon KateSaveConfigTab::icon() const | 1049 | QIcon KateSaveConfigTab::icon() const | ||
1053 | { | 1050 | { | ||
1054 | return QIcon::fromTheme(QStringLiteral("document-save")); | 1051 | return QIcon::fromTheme(QStringLiteral("document-save")); | ||
1055 | } | 1052 | } | ||
1056 | 1053 | | |||
1057 | //END KateSaveConfigTab | 1054 | //END KateSaveConfigTab | ||
1058 | 1055 | | |||
1059 | //BEGIN KateHlDownloadDialog | | |||
1060 | KateHlDownloadDialog::KateHlDownloadDialog(QWidget *parent, const char *name, bool modal) | | |||
1061 | : QDialog(parent) | | |||
1062 | { | | |||
1063 | setWindowTitle(i18n("Highlight Download")); | | |||
1064 | setObjectName(QString::fromUtf8(name)); | | |||
1065 | setModal(modal); | | |||
1066 | | ||||
1067 | QVBoxLayout *mainLayout = new QVBoxLayout; | | |||
1068 | setLayout(mainLayout); | | |||
1069 | | ||||
1070 | QLabel *label = new QLabel(i18n("Select the syntax highlighting files you want to update:"), this); | | |||
1071 | mainLayout->addWidget(label); | | |||
1072 | | ||||
1073 | list = new QTreeWidget(this); | | |||
1074 | list->setColumnCount(4); | | |||
1075 | list->setHeaderLabels({ QString(), i18n("Name"), i18n("Installed"), i18n("Latest") }); | | |||
1076 | list->setSelectionMode(QAbstractItemView::MultiSelection); | | |||
1077 | list->setAllColumnsShowFocus(true); | | |||
1078 | list->setRootIsDecorated(false); | | |||
1079 | list->setColumnWidth(0, 22); | | |||
1080 | mainLayout->addWidget(list); | | |||
1081 | | ||||
1082 | label = new QLabel(i18n("<b>Note:</b> New versions are selected automatically."), this); | | |||
1083 | mainLayout->addWidget(label); | | |||
1084 | | ||||
1085 | // buttons | | |||
1086 | QDialogButtonBox *buttons = new QDialogButtonBox(this); | | |||
1087 | mainLayout->addWidget(buttons); | | |||
1088 | | ||||
1089 | m_installButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-ok")), i18n("&Install")); | | |||
1090 | m_installButton->setDefault(true); | | |||
1091 | buttons->addButton(m_installButton, QDialogButtonBox::AcceptRole); | | |||
1092 | connect(m_installButton, SIGNAL(clicked()), this, SLOT(slotInstall())); | | |||
1093 | | ||||
1094 | QPushButton *closeButton = new QPushButton; | | |||
1095 | KGuiItem::assign(closeButton, KStandardGuiItem::cancel()); | | |||
1096 | buttons->addButton(closeButton, QDialogButtonBox::RejectRole); | | |||
1097 | connect(closeButton, SIGNAL(clicked()), this, SLOT(reject())); | | |||
1098 | | ||||
1099 | transferJob = KIO::get(QUrl(QStringLiteral("%1update-%2.%3.xml").arg(HLDOWNLOADPATH).arg(KTEXTEDITOR_VERSION_MAJOR).arg(KTEXTEDITOR_VERSION_MINOR)), KIO::Reload); | | |||
1100 | connect(transferJob, SIGNAL(data(KIO::Job*,QByteArray)), | | |||
1101 | this, SLOT(listDataReceived(KIO::Job*,QByteArray))); | | |||
1102 | // void data( KIO::Job *, const QByteArray &data); | | |||
1103 | | ||||
1104 | resize(450, 400); | | |||
1105 | } | | |||
1106 | | ||||
1107 | KateHlDownloadDialog::~KateHlDownloadDialog() {} | | |||
1108 | | ||||
1109 | /// Split typical version string (\c major.minor.patch) into | | |||
1110 | /// numeric components, convert 'em to \c unsigned and form a | | |||
1111 | /// single value that can be compared w/ other versions | | |||
1112 | /// using relation operators. | | |||
1113 | /// \note It takes into account only first 3 numbers | | |||
1114 | unsigned KateHlDownloadDialog::parseVersion(const QString &version_string) | | |||
1115 | { | | |||
1116 | unsigned vn[3] = {0, 0, 0}; | | |||
1117 | unsigned idx = 0; | | |||
1118 | foreach (const QString &n, version_string.split(QLatin1Char('.'))) { | | |||
1119 | vn[idx++] = n.toUInt(); | | |||
1120 | if (idx == sizeof(vn)) { | | |||
1121 | break; | | |||
1122 | } | | |||
1123 | } | | |||
1124 | return (((vn[0]) << 16) | ((vn[1]) << 8) | (vn[2])); | | |||
1125 | } | | |||
1126 | | ||||
1127 | void KateHlDownloadDialog::listDataReceived(KIO::Job *, const QByteArray &data) | | |||
1128 | { | | |||
1129 | if (!transferJob || transferJob->isErrorPage()) { | | |||
1130 | m_installButton->setEnabled(false); | | |||
1131 | if (data.size() == 0) { | | |||
1132 | KMessageBox::error(this, i18n("The list of highlightings could not be found on / retrieved from the server")); | | |||
1133 | } | | |||
1134 | return; | | |||
1135 | } | | |||
1136 | | ||||
1137 | listData += QLatin1String(data); | | |||
1138 | qCDebug(LOG_KTE) << QStringLiteral("CurrentListData: ") << listData; | | |||
1139 | qCDebug(LOG_KTE) << QStringLiteral("Data length: %1").arg(data.size()); | | |||
1140 | qCDebug(LOG_KTE) << QStringLiteral("listData length: %1").arg(listData.length()); | | |||
1141 | if (data.size() == 0) { | | |||
1142 | if (listData.length() > 0) { | | |||
1143 | QString installedVersion; | | |||
1144 | QDomDocument doc; | | |||
1145 | doc.setContent(listData); | | |||
1146 | QDomElement DocElem = doc.documentElement(); | | |||
1147 | QDomNode n = DocElem.firstChild(); | | |||
1148 | | ||||
1149 | if (n.isNull()) { | | |||
1150 | qCDebug(LOG_KTE) << QStringLiteral("There is no usable childnode"); | | |||
1151 | } | | |||
1152 | while (!n.isNull()) { | | |||
1153 | installedVersion = QStringLiteral(" --"); | | |||
1154 | | ||||
1155 | QDomElement e = n.toElement(); | | |||
1156 | if (!e.isNull()) { | | |||
1157 | qCDebug(LOG_KTE) << QStringLiteral("NAME: ") << e.tagName() << QStringLiteral(" - ") << e.attribute(QStringLiteral("name")); | | |||
1158 | } | | |||
1159 | n = n.nextSibling(); | | |||
1160 | | ||||
1161 | QString Name = e.attribute(QStringLiteral("name")); | | |||
1162 | QString version; | | |||
1163 | for (const auto &hl : KateHlManager::self()->modeList()) { | | |||
1164 | if (hl.name() == Name) { | | |||
1165 | version = QString::number(hl.version()); | | |||
1166 | installedVersion = QLatin1String(" ") + version; | | |||
1167 | break; | | |||
1168 | } | | |||
1169 | } | | |||
1170 | | ||||
1171 | // autoselect entry if new or updated. | | |||
1172 | QTreeWidgetItem *entry = new QTreeWidgetItem(list); | | |||
1173 | entry->setText(0, QString()); | | |||
1174 | entry->setText(1, e.attribute(QStringLiteral("name"))); | | |||
1175 | entry->setText(2, installedVersion); | | |||
1176 | entry->setText(3, e.attribute(QStringLiteral("version"))); | | |||
1177 | entry->setText(4, e.attribute(QStringLiteral("url"))); | | |||
1178 | | ||||
1179 | bool is_fresh = false; | | |||
1180 | if (!version.isEmpty()) { | | |||
1181 | unsigned prev_version = parseVersion(version); | | |||
1182 | unsigned next_version = parseVersion(e.attribute(QStringLiteral("version"))); | | |||
1183 | is_fresh = prev_version < next_version; | | |||
1184 | } else { | | |||
1185 | is_fresh = true; | | |||
1186 | } | | |||
1187 | if (is_fresh) { | | |||
1188 | entry->treeWidget()->setItemSelected(entry, true); | | |||
1189 | entry->setIcon(0, QIcon::fromTheme((QStringLiteral("get-hot-new-stuff")))); | | |||
1190 | } | | |||
1191 | } | | |||
1192 | list->resizeColumnToContents(1); | | |||
1193 | list->sortItems(1, Qt::AscendingOrder); | | |||
1194 | } | | |||
1195 | } | | |||
1196 | } | | |||
1197 | | ||||
1198 | void KateHlDownloadDialog::slotInstall() | | |||
1199 | { | | |||
1200 | const QString destdir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/org.kde.syntax-highlighting/syntax/"); | | |||
1201 | QDir(destdir).mkpath(QStringLiteral(".")); // make sure the dir is there | | |||
1202 | | ||||
1203 | foreach (QTreeWidgetItem *it, list->selectedItems()) { | | |||
1204 | QUrl src(it->text(4)); | | |||
1205 | QString filename = src.fileName(); | | |||
1206 | | ||||
1207 | // if there is no fileName construct at least something | | |||
1208 | if (filename.isEmpty()) { | | |||
1209 | filename = src.path().replace(QLatin1Char('/'), QLatin1Char('_')); | | |||
1210 | } | | |||
1211 | | ||||
1212 | QUrl dest = QUrl::fromLocalFile(destdir + filename); | | |||
1213 | | ||||
1214 | KIO::FileCopyJob *job = KIO::file_copy(src, dest); | | |||
1215 | KJobWidgets::setWindow(job, this); | | |||
1216 | job->exec(); | | |||
1217 | } | | |||
1218 | } | | |||
1219 | //END KateHlDownloadDialog | | |||
1220 | | ||||
1221 | //BEGIN KateGotoBar | 1056 | //BEGIN KateGotoBar | ||
1222 | KateGotoBar::KateGotoBar(KTextEditor::View *view, QWidget *parent) | 1057 | KateGotoBar::KateGotoBar(KTextEditor::View *view, QWidget *parent) | ||
1223 | : KateViewBarWidget(true, parent) | 1058 | : KateViewBarWidget(true, parent) | ||
1224 | , m_view(view) | 1059 | , m_view(view) | ||
1225 | { | 1060 | { | ||
1226 | Q_ASSERT(m_view != nullptr); // this bar widget is pointless w/o a view | 1061 | Q_ASSERT(m_view != nullptr); // this bar widget is pointless w/o a view | ||
1227 | 1062 | | |||
1228 | QHBoxLayout *topLayout = new QHBoxLayout(centralWidget()); | 1063 | QHBoxLayout *topLayout = new QHBoxLayout(centralWidget()); | ||
▲ Show 20 Lines • Show All 240 Lines • Show Last 20 Lines |