Changeset View
Changeset View
Standalone View
Standalone View
shell/openprojectdialog.cpp
Show All 16 Lines | |||||
17 | #include <KColorScheme> | 17 | #include <KColorScheme> | ||
18 | #include <KIO/StatJob> | 18 | #include <KIO/StatJob> | ||
19 | #include <KIO/ListJob> | 19 | #include <KIO/ListJob> | ||
20 | #include <KJobWidgets> | 20 | #include <KJobWidgets> | ||
21 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
22 | 22 | | |||
23 | #include "core.h" | 23 | #include "core.h" | ||
24 | #include "uicontroller.h" | 24 | #include "uicontroller.h" | ||
25 | #include "plugincontroller.h" | ||||
25 | #include "mainwindow.h" | 26 | #include "mainwindow.h" | ||
26 | #include "shellextension.h" | 27 | #include "shellextension.h" | ||
27 | #include "projectsourcepage.h" | 28 | #include "projectsourcepage.h" | ||
28 | #include <interfaces/iprojectcontroller.h> | 29 | #include <interfaces/iprojectcontroller.h> | ||
29 | 30 | | |||
30 | namespace KDevelop | 31 | namespace KDevelop | ||
31 | { | 32 | { | ||
kfunk: Nitpick: Don't indent inside namespaces. Aids readability in case of multi-page-long namespaces. | |||||
32 | 33 | | |||
33 | OpenProjectDialog::OpenProjectDialog( bool fetch, const QUrl& startUrl, QWidget* parent ) | 34 | OpenProjectDialog::OpenProjectDialog( bool fetch, const QUrl& startUrl, QWidget* parent ) | ||
34 | : KAssistantDialog( parent ) | 35 | : KAssistantDialog( parent ) | ||
35 | , sourcePage(nullptr) | 36 | , sourcePage(nullptr) | ||
36 | , openPage(nullptr) | 37 | , openPage(nullptr) | ||
37 | , projectInfoPage(nullptr) | 38 | , projectInfoPage(nullptr) | ||
38 | { | 39 | { | ||
39 | resize(QSize(700, 500)); | 40 | resize(QSize(700, 500)); | ||
40 | 41 | | |||
42 | QStringList filters, allEntry; | ||||
Just check KDE_FULL_SESSION once. E.g.: kfunk: Just check KDE_FULL_SESSION once.
E.g.:
`const bool useNativeFileDialog =… | |||||
43 | allEntry << "*." + ShellExtension::getInstance()->projectFileExtension(); | ||||
44 | filters << QStringLiteral("%1|%2 (%1)").arg("*." + ShellExtension::getInstance()->projectFileExtension(), ShellExtension::getInstance()->projectFileDescription()); | ||||
45 | QVector<KPluginMetaData> plugins = ICore::self()->pluginController()->queryExtensionPlugins(QStringLiteral("org.kdevelop.IProjectFileManager")); | ||||
46 | foreach(const KPluginMetaData& info, plugins) | ||||
47 | { | ||||
48 | QStringList filter = KPluginMetaData::readStringList(info.rawData(), QStringLiteral("X-KDevelop-ProjectFilesFilter")); | ||||
49 | QString desc = info.value(QStringLiteral("X-KDevelop-ProjectFilesFilterDescription")); | ||||
50 | | ||||
51 | if (!filter.isEmpty() && !desc.isEmpty()) { | ||||
52 | m_projectFilters.insert(info.name(), filter); | ||||
53 | allEntry += filter; | ||||
54 | filters << QStringLiteral("%1|%2 (%1)").arg(filter.join(QStringLiteral(" ")), desc); | ||||
55 | } | ||||
56 | } | ||||
57 | | ||||
58 | filters.prepend(i18n("%1|All Project Files (%1)", allEntry.join(QStringLiteral(" ")))); | ||||
59 | | ||||
41 | QUrl start = startUrl.isValid() ? startUrl : Core::self()->projectController()->projectsBaseDirectory(); | 60 | QUrl start = startUrl.isValid() ? startUrl : Core::self()->projectController()->projectsBaseDirectory(); | ||
42 | start = start.adjusted(QUrl::NormalizePathSegments); | 61 | start = start.adjusted(QUrl::NormalizePathSegments); | ||
43 | KPageWidgetItem* currentPage = 0; | 62 | KPageWidgetItem* currentPage = 0; | ||
44 | 63 | | |||
45 | if( fetch ) { | 64 | if( fetch ) { | ||
46 | sourcePageWidget = new ProjectSourcePage( start, this ); | 65 | sourcePageWidget = new ProjectSourcePage( start, this ); | ||
Are you sure you need ";;" here? Not " "? kfunk: Are you sure you need ";;" here? Not " "?
http://doc.qt.io/qt-5/qfiledialog.html#setNameFilters | |||||
47 | connect( sourcePageWidget, &ProjectSourcePage::isCorrect, this, &OpenProjectDialog::validateSourcePage ); | 66 | connect( sourcePageWidget, &ProjectSourcePage::isCorrect, this, &OpenProjectDialog::validateSourcePage ); | ||
48 | sourcePage = addPage( sourcePageWidget, i18n("Select Source") ); | 67 | sourcePage = addPage( sourcePageWidget, i18n("Select Source") ); | ||
49 | currentPage = sourcePage; | 68 | currentPage = sourcePage; | ||
50 | } | 69 | } | ||
51 | 70 | | |||
52 | openPageWidget = new OpenProjectPage( start, this ); | 71 | openPageWidget = new OpenProjectPage( start, filters, this ); | ||
53 | connect( openPageWidget, &OpenProjectPage::urlSelected, this, &OpenProjectDialog::validateOpenUrl ); | 72 | connect( openPageWidget, &OpenProjectPage::urlSelected, this, &OpenProjectDialog::validateOpenUrl ); | ||
54 | connect( openPageWidget, &OpenProjectPage::accepted, this, &OpenProjectDialog::openPageAccepted ); | 73 | connect( openPageWidget, &OpenProjectPage::accepted, this, &OpenProjectDialog::openPageAccepted ); | ||
55 | openPage = addPage( openPageWidget, i18n("Select a build system setup file, existing KDevelop project, " | 74 | openPage = addPage( openPageWidget, i18n("Select a build system setup file, existing KDevelop project, " | ||
56 | "or any folder to open as a project") ); | 75 | "or any folder to open as a project") ); | ||
57 | 76 | | |||
58 | if( !fetch ) { | 77 | if( !fetch ) { | ||
59 | currentPage = openPage; | 78 | currentPage = openPage; | ||
60 | } | 79 | } | ||
Show All 9 Lines | |||||
70 | setAppropriate( projectInfoPage, false ); | 89 | setAppropriate( projectInfoPage, false ); | ||
71 | 90 | | |||
72 | setCurrentPage( currentPage ); | 91 | setCurrentPage( currentPage ); | ||
73 | setWindowTitle(i18n("Open Project")); | 92 | setWindowTitle(i18n("Open Project")); | ||
74 | } | 93 | } | ||
75 | 94 | | |||
76 | void OpenProjectDialog::validateSourcePage(bool valid) | 95 | void OpenProjectDialog::validateSourcePage(bool valid) | ||
77 | { | 96 | { | ||
78 | setValid(sourcePage, valid); | 97 | setValid(sourcePage, valid); | ||
kfunk: `if (nativeDialog) ...` | |||||
kfunk: `if (nativeDialog)` -> then you also don't need to make `useKdeFileDialog` global. | |||||
79 | openPageWidget->setUrl(sourcePageWidget->workingDir()); | 98 | openPageWidget->setUrl(sourcePageWidget->workingDir()); | ||
80 | } | 99 | } | ||
Should probably factor out this block into a separate function for increased readability. kfunk: Should probably factor out this block into a separate function for increased readability. | |||||
arrowd: Uh, sorry, didn't get that. You mean factoring whole while loop? | |||||
Yes, so this reads: if (nativeDialog) { if (!execNativeDialog()) { reject(); return QDialog::Rejected; } } ... kfunk: Yes, so this reads:
```
if (nativeDialog) {
if (!execNativeDialog()) {
reject()… | |||||
81 | 100 | | |||
82 | void OpenProjectDialog::validateOpenUrl( const QUrl& url_ ) | 101 | void OpenProjectDialog::validateOpenUrl( const QUrl& url_ ) | ||
83 | { | 102 | { | ||
84 | bool isDir = false; | 103 | bool isDir = false; | ||
85 | QString extension; | 104 | QString extension; | ||
86 | bool isValid = false; | 105 | bool isValid = false; | ||
87 | 106 | | |||
88 | const QUrl url = url_.adjusted(QUrl::StripTrailingSlash); | 107 | const QUrl url = url_.adjusted(QUrl::StripTrailingSlash); | ||
89 | 108 | | |||
kfunk: Style:
```
} else {
return false;
}
``` | |||||
90 | if( url.isLocalFile() ) | 109 | if( url.isLocalFile() ) | ||
91 | { | 110 | { | ||
92 | QFileInfo info( url.toLocalFile() ); | 111 | QFileInfo info( url.toLocalFile() ); | ||
93 | isValid = info.exists(); | 112 | isValid = info.exists(); | ||
94 | if ( isValid ) { | 113 | if ( isValid ) { | ||
95 | isDir = info.isDir(); | 114 | isDir = info.isDir(); | ||
96 | extension = info.suffix(); | 115 | extension = info.suffix(); | ||
97 | } | 116 | } | ||
98 | } else if ( url.isValid() ) | 117 | } else if ( url.isValid() ) | ||
99 | { | 118 | { | ||
100 | KIO::StatJob* statJob = KIO::stat( url, KIO::HideProgressInfo ); | 119 | KIO::StatJob* statJob = KIO::stat( url, KIO::HideProgressInfo ); | ||
101 | KJobWidgets::setWindow(statJob, Core::self()->uiControllerInternal()->defaultMainWindow() ); | 120 | KJobWidgets::setWindow(statJob, Core::self()->uiControllerInternal()->defaultMainWindow() ); | ||
102 | isValid = statJob->exec(); // TODO: do this asynchronously so that the user isn't blocked while typing every letter of the hostname in sftp://hostname | 121 | isValid = statJob->exec(); // TODO: do this asynchronously so that the user isn't blocked while typing every letter of the hostname in sftp://hostname | ||
103 | if ( isValid ) { | 122 | if ( isValid ) { | ||
104 | KIO::UDSEntry entry = statJob->statResult(); | 123 | KIO::UDSEntry entry = statJob->statResult(); | ||
105 | isDir = entry.isDir(); | 124 | isDir = entry.isDir(); | ||
106 | extension = QFileInfo( entry.stringValue( KIO::UDSEntry::UDS_NAME ) ).suffix(); | 125 | extension = QFileInfo( entry.stringValue( KIO::UDSEntry::UDS_NAME ) ).suffix(); | ||
107 | } | 126 | } | ||
kfunk: `if (openPage)` | |||||
108 | } | 127 | } | ||
109 | 128 | | |||
110 | if ( isValid ) { | 129 | if ( isValid ) { | ||
111 | // reset header | 130 | // reset header | ||
112 | openPage->setHeader(i18n("Open \"%1\" as project", url.fileName())); | 131 | openPage->setHeader(i18n("Open \"%1\" as project", url.fileName())); | ||
113 | } else { | 132 | } else { | ||
114 | // report error | 133 | // report error | ||
115 | KColorScheme scheme(palette().currentColorGroup()); | 134 | KColorScheme scheme(palette().currentColorGroup()); | ||
Show All 15 Lines | 148 | { | |||
131 | m_url = url; | 150 | m_url = url; | ||
132 | if( !isDir ) { | 151 | if( !isDir ) { | ||
133 | m_url = m_url.adjusted(QUrl::StripTrailingSlash | QUrl::RemoveFilename); | 152 | m_url = m_url.adjusted(QUrl::StripTrailingSlash | QUrl::RemoveFilename); | ||
134 | } | 153 | } | ||
135 | ProjectInfoPage* page = qobject_cast<ProjectInfoPage*>( projectInfoPage->widget() ); | 154 | ProjectInfoPage* page = qobject_cast<ProjectInfoPage*>( projectInfoPage->widget() ); | ||
136 | if( page ) | 155 | if( page ) | ||
137 | { | 156 | { | ||
138 | page->setProjectName( m_url.fileName() ); | 157 | page->setProjectName( m_url.fileName() ); | ||
139 | OpenProjectPage* page2 = qobject_cast<OpenProjectPage*>( openPage->widget() ); | | |||
140 | if( page2 ) | | |||
141 | { | | |||
142 | // Default manager | 158 | // Default manager | ||
143 | page->setProjectManager( QStringLiteral("Generic Project Manager") ); | 159 | page->setProjectManager( QStringLiteral("Generic Project Manager") ); | ||
144 | // clear the filelist | 160 | // clear the filelist | ||
145 | m_fileList.clear(); | 161 | m_fileList.clear(); | ||
146 | 162 | | |||
147 | if( isDir ) { | 163 | if( isDir ) { | ||
148 | // If a dir was selected fetch all files in it | 164 | // If a dir was selected fetch all files in it | ||
149 | KIO::ListJob* job = KIO::listDir( m_url ); | 165 | KIO::ListJob* job = KIO::listDir( m_url ); | ||
150 | connect( job, &KIO::ListJob::entries, | 166 | connect( job, &KIO::ListJob::entries, | ||
151 | this, &OpenProjectDialog::storeFileList); | 167 | this, &OpenProjectDialog::storeFileList); | ||
152 | KJobWidgets::setWindow(job, Core::self()->uiController()->activeMainWindow()); | 168 | KJobWidgets::setWindow(job, Core::self()->uiController()->activeMainWindow()); | ||
153 | job->exec(); | 169 | job->exec(); | ||
154 | } else { | 170 | } else { | ||
155 | // Else we'lll just take the given file | 171 | // Else we'lll just take the given file | ||
156 | m_fileList << url.fileName(); | 172 | m_fileList << url.fileName(); | ||
157 | } | 173 | } | ||
158 | // Now find a manager for the file(s) in our filelist. | 174 | // Now find a manager for the file(s) in our filelist. | ||
159 | bool managerFound = false; | 175 | bool managerFound = false; | ||
160 | foreach( const QString& manager, page2->projectFilters().keys() ) | 176 | foreach( const QString& manager, m_projectFilters.keys() ) | ||
161 | { | 177 | { | ||
162 | foreach( const QString& filterexp, page2->projectFilters().value(manager) ) | 178 | foreach( const QString& filterexp, m_projectFilters.value(manager) ) | ||
163 | { | 179 | { | ||
164 | if( !m_fileList.filter( QRegExp( filterexp, Qt::CaseSensitive, QRegExp::Wildcard ) ).isEmpty() ) | 180 | if( !m_fileList.filter( QRegExp( filterexp, Qt::CaseSensitive, QRegExp::Wildcard ) ).isEmpty() ) | ||
165 | { | 181 | { | ||
166 | managerFound = true; | 182 | managerFound = true; | ||
167 | break; | 183 | break; | ||
168 | } | 184 | } | ||
169 | } | 185 | } | ||
170 | if( managerFound ) | 186 | if( managerFound ) | ||
171 | { | 187 | { | ||
172 | page->setProjectManager( manager ); | 188 | page->setProjectManager( manager ); | ||
173 | break; | 189 | break; | ||
174 | } | 190 | } | ||
175 | } | 191 | } | ||
176 | } | 192 | } | ||
177 | } | | |||
178 | m_url.setPath( m_url.path() + '/' + m_url.fileName() + '.' + ShellExtension::getInstance()->projectFileExtension() ); | 193 | m_url.setPath( m_url.path() + '/' + m_url.fileName() + '.' + ShellExtension::getInstance()->projectFileExtension() ); | ||
179 | } else | 194 | } else | ||
180 | { | 195 | { | ||
181 | setAppropriate( projectInfoPage, false ); | 196 | setAppropriate( projectInfoPage, false ); | ||
182 | m_url = url; | 197 | m_url = url; | ||
183 | } | 198 | } | ||
184 | validateProjectInfo(); | 199 | validateProjectInfo(); | ||
185 | setValid( openPage, true ); | 200 | setValid( openPage, true ); | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
Nitpick: Don't indent inside namespaces. Aids readability in case of multi-page-long namespaces.