forked from KDE/kdev-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploaddialog.cpp
171 lines (146 loc) · 5.58 KB
/
uploaddialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/***************************************************************************
* Copyright 2007 Niko Sams <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "uploaddialog.h"
#include <QPushButton>
#include <QHeaderView>
#include <QProgressDialog>
#include <QMenu>
#include <QContextMenuEvent>
#include <KLocalizedString>
#include <kconfiggroup.h>
#include <kmessagebox.h>
#include <kio/job.h>
#include <kio/copyjob.h>
#include <kio/jobuidelegate.h>
#include <kparts/mainwindow.h>
#include <kjobwidgets.h>
#include <interfaces/icore.h>
#include <interfaces/iuicontroller.h>
#include <interfaces/iproject.h>
#include <interfaces/iprojectcontroller.h>
#include <project/projectmodel.h>
#include "ui_uploaddialog.h"
#include "uploadprojectmodel.h"
#include "uploadprofilemodel.h"
#include "uploadprofileitem.h"
#include "uploadprofiledlg.h"
#include "uploadjob.h"
#include "kdevuploadplugin.h"
UploadDialog::UploadDialog(KDevelop::IProject* project, UploadPlugin* plugin, QWidget *parent)
: QDialog(parent), m_project(project), m_profileModel(nullptr), m_editProfileDlg(nullptr), m_plugin(plugin)
{
m_ui = new Ui::UploadDialog();
m_ui->setupUi(this);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("&Upload"));
connect(m_ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
this, SLOT(startUpload()));
m_uploadProjectModel = new UploadProjectModel(project);
m_uploadProjectModel->setSourceModel(project->projectItem()->model());
m_ui->projectTree->setModel(m_uploadProjectModel);
m_ui->projectTree->header()->hide();
connect(m_ui->profileCombobox, SIGNAL(currentIndexChanged(int)),
this, SLOT(profileChanged(int)));
m_ui->profileCombobox->setCurrentIndex(-1);
connect(m_ui->modifyProfileButton, SIGNAL(clicked()),
this, SLOT(modifyProfile()));
m_treeContextMenu = new QMenu(this);
QAction* action = new QAction(i18nc("Select all items in the tree", "All"), this);
connect(action, SIGNAL(triggered()), m_uploadProjectModel, SLOT(checkAll()));
m_treeContextMenu->addAction(action);
action = new QAction(i18n("Modified"), this);
connect(action, SIGNAL(triggered()), m_uploadProjectModel, SLOT(checkModified()));
m_treeContextMenu->addAction(action);
action = new QAction(i18n("Invert"), this);
connect(action, SIGNAL(triggered()), m_uploadProjectModel, SLOT(checkInvert()));
m_treeContextMenu->addAction(action);
m_ui->projectTree->installEventFilter(this);
}
UploadDialog::~UploadDialog()
{
delete m_ui;
delete m_editProfileDlg;
}
void UploadDialog::modifyProfile()
{
UploadProfileItem* i = m_profileModel->uploadItem(m_ui->profileCombobox->currentIndex());
if (i) {
if (!m_editProfileDlg) {
m_editProfileDlg = new UploadProfileDlg(this);
}
if (m_editProfileDlg->editProfile(i) == QDialog::Accepted) {
m_profileModel->submit();
}
}
}
void UploadDialog::profileChanged(int index)
{
UploadProfileItem* i = m_profileModel->uploadItem(index);
if (i) {
KConfigGroup c = i->profileConfigGroup();
if (c.isValid()) {
m_uploadProjectModel->setProfileConfigGroup(c);
m_ui->projectTree->setEnabled(true);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
return;
}
}
m_ui->projectTree->setEnabled(false);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
void UploadDialog::startUpload()
{
if (m_ui->profileCombobox->currentIndex() == -1) {
KMessageBox::sorry(this, i18n("Cannot upload, no profile selected."));
return;
}
UploadJob* job = new UploadJob(m_project, m_uploadProjectModel, this);
connect(job, SIGNAL(uploadFinished()), this, SLOT(uploadFinished()));
job->setOnlyMarkUploaded(m_ui->markUploadedCheckBox->checkState() == Qt::Checked);
job->setOutputModel(m_plugin->outputModel());
job->start();
}
void UploadDialog::uploadFinished()
{
hide();
}
void UploadDialog::setRootItem(KDevelop::ProjectBaseItem* item)
{
m_uploadProjectModel->setRootItem(item);
if (item) {
QModelIndex i = m_uploadProjectModel->mapFromSource(item->index());
while (i.isValid()) {
m_ui->projectTree->expand(i);
i = i.parent();
}
}
}
bool UploadDialog::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::ContextMenu) {
QContextMenuEvent *menuEvent = static_cast<QContextMenuEvent*>(event);
m_treeContextMenu->exec(menuEvent->globalPos());
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
}
void UploadDialog::setProfileModel(UploadProfileModel* model)
{
m_profileModel = model;
m_ui->profileCombobox->setModel(model);
for (int i = 0; i < m_profileModel->rowCount(); i++) {
if (m_profileModel->uploadItem(i)->isDefault()) {
m_ui->profileCombobox->setCurrentIndex(i);
break;
}
}
}
// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on