KDE/kdevelop

Andreas Pakulat apaku at gmx.de
Sat Apr 7 22:05:48 UTC 2007


SVN commit 651493 by apaku:

Implement remote-project loading, currently this is limited to developer-dependant changes, i.e. only the .kdev4/<projectname>.kdev4 file will be uploaded on changes. As soon as there's a GUI for changing the normal project file the rest will be added
ATTENTION:
Also renamed the Name and Manager items in the project files to Project Name and Project Manager, so adapt your test projects.
CCMAIL:kdevelop-devel at kdevelop.org


 M  +2 -2      languages/cpp/app_templates/qmake_qt4guiapp/%{APPNAMELC}.kdev4  
 M  +3 -2      lib/interfaces/iproject.h  
 M  +106 -4    lib/project/projectconfigskeleton.cpp  
 M  +9 -3      lib/project/projectconfigskeleton.h  
 M  +4 -2      lib/project/projectkcmodule.h  
 M  +89 -16    lib/shell/project.cpp  
 M  +4 -2      lib/shell/project.h  
 M  +6 -4      lib/shell/projectcontroller.cpp  


--- trunk/KDE/kdevelop/languages/cpp/app_templates/qmake_qt4guiapp/%{APPNAMELC}.kdev4 #651492:651493
@@ -1,5 +1,5 @@
 [General Options]
-Builder=KDevMakeBuilder
-Manager=KDevQMakeManager
+Project Builder=KDevMakeBuilder
+Project Manager=KDevQMakeManager
 PrimaryLanguage=C++
 ProjectManagementView=KDevProjectManagerView
--- trunk/KDE/kdevelop/lib/interfaces/iproject.h #651492:651493
@@ -83,8 +83,9 @@
 
     virtual ProjectFileItem *fileForUrl( const KUrl& ) const = 0;
 
-    virtual KUrl projectConfigFile() const = 0;
-    virtual KUrl projectDefaultsConfigFile() const = 0;
+//     virtual KUrl projectConfigFile() const = 0;
+//     virtual KUrl projectDefaultsConfigFile() const = 0;
+    virtual KUrl projectFileUrl() const = 0;
     virtual KSharedConfig::Ptr projectConfiguration() const = 0;
 //     virtual void setLocalFile( const KUrl& ) = 0;
 //     virtual void setGlobalFile( const KUrl& ) = 0;
--- trunk/KDE/kdevelop/lib/project/projectconfigskeleton.cpp #651492:651493
@@ -21,28 +21,130 @@
 #include "projectconfigskeleton.h"
 #include "iproject.h"
 
+#include <kio/netaccess.h>
+
 namespace KDevelop
 {
 
+struct ProjectConfigSkeletonPrivate
+{
+    QString m_developerTempFile;
+    QString m_projectTempFile;
+    KUrl m_projectFileUrl;
+    KUrl m_developerFileUrl;
+    bool mUseDefaults;
+};
+
 ProjectConfigSkeleton::ProjectConfigSkeleton( const QString & configname )
-        : KConfigSkeleton( configname )
+        : KConfigSkeleton( configname ), d( new ProjectConfigSkeletonPrivate )
 {
+    d->m_projectTempFile = configname;
 }
 
 ProjectConfigSkeleton::ProjectConfigSkeleton( KSharedConfig::Ptr config )
-        : KConfigSkeleton( config )
+        : KConfigSkeleton( config ), d( new ProjectConfigSkeletonPrivate )
 {
 }
 
-void ProjectConfigSkeleton::setProjectConfig( const QString& cfg )
+void ProjectConfigSkeleton::setDeveloperTempFile( const QString& cfg )
 {
+    d->m_developerTempFile = cfg;
     config()->setExtraConfigFiles( QStringList() << cfg );
     config()->reparseConfiguration();
     readConfig();
 }
 
+void ProjectConfigSkeleton::setProjectFileUrl( const QString& cfg )
+{
+    d->m_projectFileUrl = KUrl(cfg);
+}
+
+void ProjectConfigSkeleton::setDeveloperFileUrl( const QString& cfg )
+{
+    d->m_developerFileUrl = KUrl(cfg);
+}
+
+void ProjectConfigSkeleton::usrSetDefaults()
+{
+    kDebug(9000) << "Setting Defaults" << endl;
+    KConfig cfg( d->m_projectTempFile );
+    Q_FOREACH( KConfigSkeletonItem* item, items() )
+    {
+        item->swapDefault();
+        if( cfg.hasGroup( item->group() ) )
+        {
+            KConfigGroup grp = cfg.group( item->group() );
+            item->setProperty( grp.readEntry( item->key(), item->property() ) );
+        }
+    }
+}
+
+bool ProjectConfigSkeleton::usrUseDefaults( bool b )
+{
+    if( b == d->mUseDefaults )
+        return d->mUseDefaults;
+
+    if( b )
+    {
+        KConfig cfg( d->m_projectTempFile );
+        Q_FOREACH( KConfigSkeletonItem* item, items() )
+        {
+            kDebug(9000) << item->key() << "|" << item->property() << endl;
+            item->swapDefault();
+            kDebug(9000) << item->key() << "|" << item->property() << endl;
+                KConfigGroup grp = cfg.group( item->group() );
+            kDebug( 9000 ) << grp.readEntry( item->key(), item->property() ) << endl;
+            if( cfg.hasGroup( item->group() ) )
+            {
+                kDebug(9000) << "reading" << endl;
+//                 KConfigGroup grp = cfg.group( item->group() );
+                item->setProperty( grp.readEntry( item->key(), item->property() ) );
+            }
+        }
+    }else
+    {
+        KConfig cfg( d->m_developerTempFile );
+        KConfig defCfg( d->m_projectTempFile );
+        Q_FOREACH( KConfigSkeletonItem* item, items() )
+        {
+            if( cfg.hasGroup( item->group() ) )
+            {
+                KConfigGroup grp = cfg.group( item->group() );
+                item->setProperty( grp.readEntry( item->key(), item->property() ) );
+            }else
+            {
+                KConfigGroup grp = defCfg.group( item->group() );
+                item->setProperty( grp.readEntry( item->key(), item->property() ) );
+            }
+        }
+    }
+    d->mUseDefaults = b;
+    return !d->mUseDefaults;
+}
+
+void ProjectConfigSkeleton::usrWriteConfig()
+{
+    KConfigSkeletonItem::List myitems = items();
+    KConfigSkeletonItem::List::ConstIterator it;
+    for( it = myitems.begin(); it != myitems.end(); ++it )
+    {
+        (*it)->writeConfig( config() );
+    }
+
+    config()->sync();
+
+    readConfig();
+
+    KIO::NetAccess::upload( d->m_developerTempFile, d->m_developerFileUrl, 0 );
+
+    emit configChanged();
+
+}
+
 ProjectConfigSkeleton::~ProjectConfigSkeleton()
-{}
+{
+    delete d;
+}
 
 }
 #include "projectconfigskeleton.moc"
--- trunk/KDE/kdevelop/lib/project/projectconfigskeleton.h #651492:651493
@@ -43,8 +43,13 @@
 
     virtual ~ProjectConfigSkeleton();
 
-    void setProjectConfig( const QString& );
-
+    void setDeveloperTempFile( const QString& );
+    void setProjectFileUrl( const QString& );
+    void setDeveloperFileUrl( const QString& );
+protected:
+    void usrSetDefaults();
+    bool usrUseDefaults( bool b );
+    void usrWriteConfig();
 private:
     /**
      * There's no way in KDE4 API to find out the file that the config object
@@ -53,7 +58,8 @@
      * this constructor is used and see if we need to add apropriate API to
      * kdelibs
      */
-    ProjectConfigSkeleton( KSharedConfig::Ptr config );
+     ProjectConfigSkeleton( KSharedConfig::Ptr config );
+     struct ProjectConfigSkeletonPrivate * const d;
 };
 
 }
--- trunk/KDE/kdevelop/lib/project/projectkcmodule.h #651492:651493
@@ -33,9 +33,11 @@
         ProjectKCModule( const KComponentData& componentData, QWidget* parent, const QStringList& args )
             : KCModule( componentData, parent, args )
         {
-            Q_ASSERT( args.count() > 1 );
+            Q_ASSERT( args.count() > 3 );
             T::instance( args.first() );
-            T::self()->setProjectConfig( args.at(1) );
+            T::self()->setDeveloperTempFile( args.at(1) );
+            T::self()->setProjectFileUrl( args.at(2) );
+            T::self()->setDeveloperFileUrl( args.at(3) );
         }
         virtual ~ProjectKCModule() {}
 };
--- trunk/KDE/kdevelop/lib/shell/project.cpp #651492:651493
@@ -37,9 +37,11 @@
 #include <kconfiggroup.h>
 #include <klocale.h>
 #include <kio/job.h>
+#include <kio/netaccess.h>
 #include <kio/global.h>
 #include <kmessagebox.h>
 #include <kio/jobclasses.h>
+#include <ktemporaryfile.h>
 
 #include "core.h"
 #include "iplugin.h"
@@ -60,12 +62,15 @@
 {
 public:
     KUrl folder;
+    KUrl projectFileUrl;
+    KUrl developerFileUrl;
+    QString developerTempFile;
+    QString projectTempFile;
+    KTemporaryFile* tmp;
     IPlugin* manager;
 //     IPersistentHash persistentHash;
     ProjectItem* topItem;
     QString name;
-    KUrl localFile;
-    KUrl globalFile;
     KSharedConfig::Ptr m_cfg;
     QList<ProjectFileItem*> recurseFiles( ProjectBaseItem * projectItem )
     {
@@ -112,6 +117,7 @@
 
     d->manager = 0;
     d->topItem = 0;
+    d->tmp = 0;
 }
 
 Project::~Project()
@@ -124,14 +130,14 @@
     return d->name;
 }
 
-KUrl Project::projectConfigFile() const
+QString Project::developerTempFile() const
 {
-    return d->localFile;
+    return d->developerTempFile;
 }
 
-KUrl Project::projectDefaultsConfigFile() const
+QString Project::projectTempFile() const
 {
-    return d->globalFile;
+    return d->projectTempFile;
 }
 
 KSharedConfig::Ptr Project::projectConfiguration() const
@@ -166,12 +172,60 @@
         return false;
     }
 
-    KConfig projectConfig( projectFileUrl.pathOrUrl() );
-    KConfigGroup projectGroup( &projectConfig, "General Options" );
+    d->projectFileUrl = projectFileUrl;
+    d->developerFileUrl = KUrl( projectFileUrl.directory( KUrl::AppendTrailingSlash )
+                                  + ".kdev4/"
+                                  + projectFileUrl.fileName() );
 
-    d->name = projectGroup.readEntry( "Name", projectFileUrl.fileName() );
+    statJob = KIO::stat( d->developerFileUrl );
+    if( !statJob->exec() )
+    {
+        KUrl dir = KUrl( projectFileUrl.directory( KUrl::AppendTrailingSlash ) + ".kdev4");
+        statJob = KIO::stat( projectFileUrl );
+        if( !statJob->exec() )
+        {
+            KIO::SimpleJob* mkdirJob = KIO::mkdir( dir );
+            if( !mkdirJob->exec() )
+            {
+                KMessageBox::sorry(
+                        Core::self()->uiControllerInternal()->activeMainWindow(),
+                        i18n("Unable to create hidden dir (%1) for developer file",
+                        dir.pathOrUrl() )
+                        );
+                return false;
+            }
+        }
+    }
+
+    if( !KIO::NetAccess::download( d->projectFileUrl, d->projectTempFile,
+                        Core::self()->uiControllerInternal()->activeMainWindow() ) )
+    {
+        KMessageBox::sorry( Core::self()->uiControllerInternal()->activeMainWindow(),
+                            i18n("Unable to get project file: %1",
+                            d->projectFileUrl.pathOrUrl() ) );
+        return false;
+
+    }
+
+    statJob = KIO::stat( d->developerFileUrl );
+    if( !statJob->exec() || !KIO::NetAccess::download( d->developerFileUrl, d->developerTempFile,
+            Core::self()->uiControllerInternal()->activeMainWindow() ) )
+    {
+
+        d->tmp = new KTemporaryFile();
+        d->tmp->open();
+        d->tmp->close();
+        d->developerTempFile = d->tmp->fileName();
+    }
+
+    d->m_cfg = KSharedConfig::openConfig( d->projectTempFile );
+    d->m_cfg->setExtraConfigFiles( QStringList() << d->developerTempFile );
+
+    KConfigGroup projectGroup( d->m_cfg, "General Options" );
+
+    d->name = projectGroup.readEntry( "Project Name", projectFileUrl.fileName() );
     d->folder = projectFileUrl.directory();
-    QString managerSetting = projectGroup.readEntry( "Manager", "KDevGenericManager" );
+    QString managerSetting = projectGroup.readEntry( "Project Manager", "KDevGenericManager" );
 
     //Get our importer
     IPluginController* pluginManager = Core::self()->pluginController();
@@ -205,12 +259,7 @@
         d->manager = 0;
         return false;
     }
-    d->globalFile = projectFileUrl;
-    d->localFile = KUrl( projectFileUrl.directory( KUrl::AppendTrailingSlash )
-                                  + ".kdev4/"
-                                  + projectFileUrl.fileName() );
-    d->m_cfg = KSharedConfig::openConfig( d->globalFile.path() );
-    d->m_cfg->setExtraConfigFiles( QStringList() << d->localFile.path() );
+
     return true;
 }
 
@@ -228,6 +277,20 @@
     QList<QStandardItem*> itemList = Core::self()->projectController()->projectModel()->takeRow( d->topItem->row() );
     qDeleteAll( itemList );
 
+    if( d->tmp )
+    {
+        d->tmp->close();
+    }
+
+    if( !KIO::NetAccess::upload( d->developerTempFile, d->developerFileUrl,
+                Core::self()->uiControllerInternal()->activeMainWindow() ) )
+    {
+        KMessageBox::sorry( Core::self()->uiControllerInternal()->activeMainWindow(),
+                    i18n("Couldn't store developer specific project configuration.\n"
+                         "Attention: The project settings you changed will be lost."
+                    ) );
+    }
+    delete d->tmp;
 }
 bool Project::inProject( const KUrl& url ) const
 {
@@ -341,7 +404,17 @@
 //     return &d->persistentHash;
 // }
 
+KUrl Project::projectFileUrl() const
+{
+    return d->projectFileUrl;
 }
 
+KUrl Project::developerFileUrl() const
+{
+    return d->developerFileUrl;
+}
+
+}
+
 #include "project.moc"
 // kate: space-indent on; indent-width 4; tab-width: 4; replace-tabs on; auto-insert-doxygen on
--- trunk/KDE/kdevelop/lib/shell/project.h #651492:651493
@@ -75,8 +75,10 @@
 
     virtual ProjectFileItem *fileForUrl( const KUrl& ) const;
 
-    virtual KUrl projectConfigFile() const;
-    virtual KUrl projectDefaultsConfigFile() const;
+    QString projectTempFile() const;
+    QString developerTempFile() const;
+    KUrl developerFileUrl() const;
+    virtual KUrl projectFileUrl() const;
     virtual KSharedConfig::Ptr projectConfiguration() const;
 
 public Q_SLOTS:
--- trunk/KDE/kdevelop/lib/shell/projectcontroller.cpp #651492:651493
@@ -67,15 +67,17 @@
     {
         if( !obj )
             return;
-        IProject* proj = qobject_cast<IProject*>(obj);
+        Project* proj = qobject_cast<Project*>(obj);
         if( !proj )
             return;
         if( !m_cfgDlgs.contains( proj ) )
             m_cfgDlgs[proj] = new KSettings::Dialog( findPluginsForProject( proj ),
                                                      KSettings::Dialog::Static,
                                                      m_core->uiController()->activeMainWindow(),
-                                                     QStringList() << proj->projectDefaultsConfigFile().path()
-                                                        << proj->projectConfigFile().path() );
+                                                     QStringList() << proj->projectTempFile()
+                                                         << proj->developerTempFile()
+                                                         << proj->projectFileUrl().url()
+                                                         << proj->developerFileUrl().url() );
 
         m_cfgDlgs[proj]->show();
     }
@@ -196,7 +198,7 @@
 
     foreach( IProject* project, d->m_projects )
     {
-        if ( url == project->projectDefaultsConfigFile() )
+        if ( url == project->projectFileUrl() )
         {
             if ( KMessageBox::questionYesNo( d->m_core->uiControllerInternal()->defaultMainWindow(),
                                              i18n( "Reopen the current project?" ) )




More information about the KDevelop-devel mailing list