KDE/kdevelop/plugins/appwizard

Andreas Pakulat apaku at gmx.de
Sun Nov 16 21:23:21 UTC 2008


SVN commit 885255 by apaku:

Improve usability of the new project wizard. Automatically append the
project name to the url, until the user edits the url. From that point
on it accepts the users choice and doesn't change the url anymore.

I'm not sure wether this is the best way of doing it or not, so CC'ing
the list to get some more input/feedback.

Another option I currently see is allowing to edit the url, but going
back to appending the appname once the user again changes the
application name. Is that more intuitive?

CCMAIL: kdevelop-devel at kdevelop.org

 M  +0 -6      appwizarddialog.cpp  
 M  +2 -2      appwizardplugin.cpp  
 M  +95 -21    projectselectionpage.cpp  
 M  +5 -0      projectselectionpage.h  
 M  +1 -1      projectselectionpage.ui  


--- trunk/KDE/kdevelop/plugins/appwizard/appwizarddialog.cpp #885254:885255
@@ -60,12 +60,6 @@
     ApplicationInfo a;
     a.name = m_selectionPage->appName();
     a.location = m_selectionPage->location();
-    //correct place?
-    if (QFile::exists(a.location.toLocalFile()))
-    {
-        QDir tDir;
-        tDir.mkdir( a.location.toLocalFile() );
-    }
     a.appTemplate = m_selectionPage->selectedTemplate();
     if( !m_vcsPage->pluginName().isEmpty() )
     {
--- trunk/KDE/kdevelop/plugins/appwizard/appwizardplugin.cpp #885254:885255
@@ -264,7 +264,7 @@
         {
             if( !QFileInfo( dest.toLocalFile() ).exists() )
             {
-                QDir::root().mkdir( dest.toLocalFile() );
+                QDir::root().mkpath( dest.toLocalFile() );
             }
             unpackDir = dest.toLocalFile(); //in DVCS we unpack template directly to the project's directory
         }
@@ -274,7 +274,7 @@
             parentdir.cd( ".." );
             if( !QFileInfo( parentdir.toLocalFile() ).exists() )
             {
-                QDir::root().mkdir( parentdir.toLocalFile() );
+                QDir::root().mkpath( parentdir.toLocalFile() );
             }
         }
 
--- trunk/KDE/kdevelop/plugins/appwizard/projectselectionpage.cpp #885254:885255
@@ -11,22 +11,24 @@
 
 #include <QDir>
 
+#include <klineedit.h>
+
 #include "ui_projectselectionpage.h"
 #include "projecttemplatesmodel.h"
 
 ProjectSelectionPage::ProjectSelectionPage(ProjectTemplatesModel *templatesModel, QWidget *parent)
-    :QWidget(parent), m_templatesModel(templatesModel)
+    :QWidget(parent), m_templatesModel(templatesModel), m_urlEditedByUser( false )
 {
     ui = new Ui::ProjectSelectionPage();
     ui->setupUi(this);
     ui->templateView->setModel(templatesModel);
 
     ui->locationUrl->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
-    connect( ui->locationUrl, SIGNAL(textChanged(const QString&)),
-             this, SLOT(validateData() ));
+    connect( ui->locationUrl->lineEdit(), SIGNAL(textEdited(const QString&)),
+             this, SLOT(urlEdited() ));
     connect( ui->locationUrl, SIGNAL(urlSelected(const KUrl&)),
-             this, SLOT(validateData() ));
-    connect( ui->templateView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), 
+             this, SLOT(urlEdited() ));
+    connect( ui->templateView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
              this, SLOT( validateData() ) );
     connect( ui->appNameEdit, SIGNAL(textEdited(const QString&)),
              this, SLOT( validateData() ) );
@@ -49,7 +51,9 @@
 
 KUrl ProjectSelectionPage::location()
 {
-    return ui->locationUrl->url();
+    KUrl tUrl = ui->locationUrl->url();
+    tUrl.addPath( encodedAppName() );
+    return tUrl;
 }
 
 QString ProjectSelectionPage::appName()
@@ -57,41 +61,86 @@
     return ui->appNameEdit->text();
 }
 
+void ProjectSelectionPage::urlEdited()
+{
+    m_urlEditedByUser = true;
+    validateData();
+    emit locationChanged( ui->locationUrl->url() );
+}
+
 void ProjectSelectionPage::validateData()
 {
-    KUrl url = ui->locationUrl->url();
-    if( !url.isLocalFile() )
+    KUrl url;
+    if( m_urlEditedByUser )
     {
+        url = ui->locationUrl->url();
+    } else
+    {
+        url = KUrl( QDir::homePath() );
+    }
+    if( !url.isLocalFile() || url.isEmpty())
+    {
         ui->locationValidLabel->setText( i18n("Invalid Location") );
         emit invalid();
         return;
     }
-    QFileInfo fi( url.toLocalFile( KUrl::RemoveTrailingSlash ) );
-    if( fi.exists() && fi.isDir() )
+
+    if( appName().isEmpty() )
     {
-           if( !QDir( fi.absoluteFilePath()).entryList().isEmpty() )
-           {
-                ui->locationValidLabel->setText( i18n("Directory already exists and is not empty!") );
-                emit invalid();
-                return;
-           }
+        ui->locationValidLabel->setText( i18n("Empty project name") );
+        emit invalid();
+        return;
     }
 
-    if( ui->appNameEdit->text().isEmpty() )
+    if( appName() == "." || appName() == "..")
     {
-        ui->locationValidLabel->setText( i18n("Empty project name") );
+        ui->locationValidLabel->setText( i18n("Invalid project name") );
         emit invalid();
         return;
     }
 
+    QDir tDir(url.toLocalFile( KUrl::RemoveTrailingSlash ));
+    while (!tDir.exists() && !tDir.isRoot())
+        tDir.setPath( pathUp( tDir.absolutePath() ));
+
+    if (tDir.exists())
+    {
+        QFileInfo tFileInfo(tDir.absolutePath());
+        if (!tFileInfo.isWritable() || !tFileInfo.isExecutable())
+        {
+            ui->locationValidLabel->setText( i18n("Unabled to create subdirectories, "
+                                                  "missing permissions on: %1", tDir.absolutePath()) );
+            emit invalid();
+            return;
+        }
+    }
+
+    if( !m_urlEditedByUser )
+    {
+        url.addPath( encodedAppName() );
+    }
+    QFileInfo fi( url.toLocalFile( KUrl::RemoveTrailingSlash ) );
+    if( fi.exists() && fi.isDir() )
+    {
+        if( !QDir( fi.absoluteFilePath()).entryList( QDir::NoDotAndDotDot | QDir::AllEntries ).isEmpty() )
+        {
+            ui->locationValidLabel->setText( i18n("Directory already exists and is not empty!") );
+            emit invalid();
+            return;
+        }
+    }
+
     QStandardItem* item = m_templatesModel->itemFromIndex( ui->templateView->currentIndex() );
     if( item && !item->hasChildren() )
     {
-        ui->locationValidLabel->setText( i18n("Valid Location") );
+        ui->locationValidLabel->setText( url.path( KUrl::RemoveTrailingSlash ) );
+        if( !m_urlEditedByUser )
+        {
+            ui->locationUrl->setPath( url.path( KUrl::RemoveTrailingSlash ) );
+        }
         emit valid();
-        emit locationChanged( url );
         return;
-    } else 
+    } else
     {
         ui->locationValidLabel->setText( i18n("Invalid Project Template") );
         emit invalid();
@@ -101,4 +150,29 @@
     emit invalid();
 }
 
+QByteArray ProjectSelectionPage::encodedAppName()
+{
+    // : < > * ? / \ | " are invalid on windows
+    QByteArray tEncodedName = appName().toUtf8();
+    for (int i = 0; i < tEncodedName.size(); ++i)
+    {
+        QChar tChar(tEncodedName.at( i ));
+        if (tChar.isDigit() || tChar.isSpace() || tChar.isLetter() || tChar == '%')
+            continue;
+
+        QByteArray tReplace = QUrl::toPercentEncoding( tChar );
+        tEncodedName.replace( tEncodedName.at( i ) ,tReplace );
+        i =  i + tReplace.size() - 1;
+    }
+    return tEncodedName;
+}
+
+QString ProjectSelectionPage::pathUp(const QString& aPath)
+{
+    QString tPath = aPath;
+    int tIndex = tPath.lastIndexOf( QDir::separator() );
+    tPath = tPath.remove(tIndex, tPath.length() - tIndex);
+    return tPath;
+}
+
 #include "projectselectionpage.moc"
--- trunk/KDE/kdevelop/plugins/appwizard/projectselectionpage.h #885254:885255
@@ -33,10 +33,15 @@
     void valid();
     void invalid();
 private slots:
+    void urlEdited();
     void validateData();
 private:
+    inline QByteArray encodedAppName();
+    inline QString pathUp(const QString& aPath);
+
     Ui::ProjectSelectionPage *ui;
     ProjectTemplatesModel *m_templatesModel;
+    bool m_urlEditedByUser;
 };
 
 #endif
--- trunk/KDE/kdevelop/plugins/appwizard/projectselectionpage.ui #885254:885255
@@ -49,7 +49,7 @@
        </widget>
       </item>
       <item row="2" column="1" >
-       <widget class="QLabel" name="locationValidLabel" >
+       <widget class="KSqueezedTextLabel" name="locationValidLabel" >
         <property name="text" >
          <string>(invalid)</string>
         </property>




More information about the KDevelop-devel mailing list