Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
925182ff
Commit
925182ff
authored
Aug 06, 2010
by
ck
Browse files
Maemo: Create .desktop files for all application (sub-)projects.
parent
e7a8cad1
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp
View file @
925182ff
...
...
@@ -161,10 +161,8 @@ bool MaemoPackageCreationStep::createPackage()
.
arg
(
debianDirPath
));
return
false
;
}
const
QString
templatesDirPath
=
buildConfiguration
()
->
target
()
->
project
()
->
projectDirectory
()
+
QLatin1Char
(
'/'
)
+
MaemoTemplatesManager
::
PackagingDirName
+
QLatin1String
(
"/debian"
);
const
QString
templatesDirPath
=
MaemoTemplatesManager
::
instance
()
->
debianDirPath
(
buildConfiguration
()
->
target
()
->
project
());
QDir
templatesDir
(
templatesDirPath
);
const
QStringList
&
files
=
templatesDir
.
entryList
(
QDir
::
Files
);
foreach
(
const
QString
&
fileName
,
files
)
{
...
...
src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.cpp
View file @
925182ff
...
...
@@ -58,9 +58,10 @@ namespace Internal {
namespace
{
const
QByteArray
IconFieldName
(
"XB-Maemo-Icon-26:"
);
const
QString
MaemoDirName
(
"maemo"
);
const
QString
PackagingDirName
=
MaemoDirName
+
QLatin1Char
(
'/'
)
+
(
"packaging"
);
}
// anonymous namespace
const
QLatin1String
MaemoTemplatesManager
::
PackagingDirName
(
"packaging"
);
MaemoTemplatesManager
*
MaemoTemplatesManager
::
m_instance
=
0
;
...
...
@@ -80,7 +81,7 @@ MaemoTemplatesManager::MaemoTemplatesManager(QObject *parent) : QObject(parent)
this
,
SLOT
(
handleActiveProjectChanged
(
ProjectExplorer
::
Project
*
)));
connect
(
session
,
SIGNAL
(
aboutToRemoveProject
(
ProjectExplorer
::
Project
*
)),
this
,
SLOT
(
handleProjectToBeRemoved
(
ProjectExplorer
::
Project
*
)));
handleActiveProjectChanged
(
session
->
startupProject
());
handleActiveProjectChanged
(
session
->
startupProject
());
}
void
MaemoTemplatesManager
::
handleActiveProjectChanged
(
ProjectExplorer
::
Project
*
project
)
...
...
@@ -91,43 +92,51 @@ void MaemoTemplatesManager::handleActiveProjectChanged(ProjectExplorer::Project
connect
(
project
,
SIGNAL
(
activeTargetChanged
(
ProjectExplorer
::
Target
*
)),
this
,
SLOT
(
handleTarget
(
ProjectExplorer
::
Target
*
)));
const
QList
<
Target
*>
&
targets
=
project
->
targets
();
foreach
(
Target
*
const
target
,
targets
)
handleTarget
(
target
);
foreach
(
Target
*
const
target
,
targets
)
{
if
(
handleTarget
(
target
))
{
QFileSystemWatcher
*
const
fsWatcher
=
new
QFileSystemWatcher
(
this
);
fsWatcher
->
addPath
(
debianDirPath
(
project
));
fsWatcher
->
addPath
(
changeLogFilePath
(
project
));
fsWatcher
->
addPath
(
controlFilePath
(
project
));
connect
(
fsWatcher
,
SIGNAL
(
directoryChanged
(
QString
)),
this
,
SLOT
(
handleDebianDirContentsChanged
()));
connect
(
fsWatcher
,
SIGNAL
(
fileChanged
(
QString
)),
this
,
SLOT
(
handleDebianFileChanged
(
QString
)));
handleDebianDirContentsChanged
();
handleDebianFileChanged
(
changeLogFilePath
(
project
));
handleDebianFileChanged
(
controlFilePath
(
project
));
connect
(
qobject_cast
<
Qt4Project
*>
(
project
),
SIGNAL
(
proFileUpdated
(
Qt4ProjectManager
::
Internal
::
Qt4ProFileNode
*
)),
this
,
SLOT
(
handleProFileUpdated
(
Qt4ProjectManager
::
Internal
::
Qt4ProFileNode
*
)),
Qt
::
QueuedConnection
);
m_maemoProjects
.
insert
(
project
,
fsWatcher
);
}
}
}
}
void
MaemoTemplatesManager
::
handleTarget
(
ProjectExplorer
::
Target
*
target
)
bool
MaemoTemplatesManager
::
handleTarget
(
ProjectExplorer
::
Target
*
target
)
{
if
(
!
target
||
target
->
id
()
!=
QLatin1String
(
Constants
::
MAEMO_DEVICE_TARGET_ID
))
return
;
if
(
!
createTemplatesIfNecessary
(
target
))
return
;
Project
*
const
project
=
target
->
project
();
QFileSystemWatcher
*
const
fsWatcher
=
new
QFileSystemWatcher
(
this
);
fsWatcher
->
addPath
(
debianDirPath
(
project
));
fsWatcher
->
addPath
(
changeLogFilePath
(
project
));
fsWatcher
->
addPath
(
controlFilePath
(
project
));
connect
(
fsWatcher
,
SIGNAL
(
directoryChanged
(
QString
)),
this
,
SLOT
(
handleDebianDirContentsChanged
()));
connect
(
fsWatcher
,
SIGNAL
(
fileChanged
(
QString
)),
this
,
SLOT
(
handleDebianFileChanged
(
QString
)));
handleDebianDirContentsChanged
();
handleDebianFileChanged
(
changeLogFilePath
(
project
));
handleDebianFileChanged
(
controlFilePath
(
project
));
m_maemoProjects
.
insert
(
project
,
fsWatcher
);
return
false
;
if
(
!
createDebianTemplatesIfNecessary
(
target
))
return
false
;
if
(
!
syncDesktopFiles
(
target
))
return
false
;
return
true
;
}
bool
MaemoTemplatesManager
::
createTemplatesIfNecessary
(
const
ProjectExplorer
::
Target
*
target
)
bool
MaemoTemplatesManager
::
create
Debian
TemplatesIfNecessary
(
const
ProjectExplorer
::
Target
*
target
)
{
Project
*
const
project
=
target
->
project
();
QDir
projectDir
(
project
->
projectDirectory
());
if
(
projectDir
.
exists
(
Packaging
DirName
))
if
(
projectDir
.
exists
(
Maemo
DirName
))
return
true
;
const
QString
packagingTemplatesDir
=
projectDir
.
path
()
+
QLatin1Char
(
'/'
)
+
PackagingDirName
;
if
(
!
projectDir
.
mk
dir
(
PackagingDirName
))
{
if
(
!
projectDir
.
mk
path
(
PackagingDirName
))
{
raiseError
(
tr
(
"Could not create directory '%1'."
)
.
arg
(
QDir
::
toNativeSeparators
(
packagingTemplatesDir
)));
return
false
;
...
...
@@ -207,6 +216,80 @@ bool MaemoTemplatesManager::createTemplatesIfNecessary(const ProjectExplorer::Ta
return
true
;
}
bool
MaemoTemplatesManager
::
syncDesktopFiles
(
const
ProjectExplorer
::
Target
*
target
)
{
const
QByteArray
desktopTemplate
(
"[Desktop Entry]
\n
Encoding=UTF-8
\n
"
"Version=1.0
\n
Type=Application
\n
Terminal=false
\n
Name=topx
\n
Exec=
\n
"
"Icon=
\n
X-Window-Icon=
\n
X-HildonDesk-ShowInToolbar=true
\n
"
"X-Osso-Type=application/x-executable
\n
"
);
const
Qt4Target
*
const
qt4Target
=
qobject_cast
<
const
Qt4Target
*>
(
target
);
Q_ASSERT_X
(
qt4Target
,
Q_FUNC_INFO
,
"Impossible: Target has Maemo id, but could not be cast to Qt4Target."
);
const
QList
<
Qt4ProFileNode
*>
&
applicationProjects
=
qt4Target
->
qt4Project
()
->
applicationProFiles
();
QList
<
QString
>
applicationProjectNames
;
foreach
(
const
Qt4ProFileNode
*
const
subProject
,
applicationProjects
)
applicationProjectNames
<<
subProject
->
displayName
();
const
QString
maemoDirPath
=
target
->
project
()
->
projectDirectory
()
+
QLatin1Char
(
'/'
)
+
MaemoDirName
;
QDir
maemoDir
(
maemoDirPath
);
const
QStringList
&
desktopFiles
=
maemoDir
.
entryList
(
QStringList
()
<<
QLatin1String
(
"*.desktop"
),
QDir
::
Files
);
QStringList
filesToAdd
;
QStringList
filesToRemove
;
// Step 1: Remove all desktop files that refer to projects that don't exist anymore.
foreach
(
const
QString
&
desktopFile
,
desktopFiles
)
{
const
QString
projectName
=
QFileInfo
(
desktopFile
).
completeBaseName
();
if
(
!
applicationProjectNames
.
contains
(
projectName
))
{
const
QString
&
absFilePath
=
maemoDirPath
+
QLatin1Char
(
'/'
)
+
desktopFile
;
if
(
!
QFile
::
remove
(
absFilePath
))
{
qWarning
(
"Failed to remove outdated project file %s."
,
qPrintable
(
absFilePath
));
}
filesToRemove
<<
absFilePath
;
}
}
// Step 2: Create a desktop file for every project that doesn't have one.
foreach
(
const
QString
&
projectName
,
applicationProjectNames
)
{
const
QString
&
desktopFileName
=
projectName
+
QLatin1String
(
".desktop"
);
if
(
!
desktopFiles
.
contains
(
desktopFileName
))
{
const
QString
&
absFilePath
=
maemoDirPath
+
QLatin1Char
(
'/'
)
+
desktopFileName
;
QFile
desktopFile
(
absFilePath
);
if
(
!
desktopFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
(
"Failed to create desktop file %s"
,
qPrintable
(
absFilePath
));
continue
;
}
filesToAdd
<<
absFilePath
;
if
(
desktopFile
.
write
(
desktopTemplate
)
!=
desktopTemplate
.
length
())
{
qWarning
(
"Failed to write to desktop file %s"
,
qPrintable
(
absFilePath
));
continue
;
}
}
}
if
(
!
filesToAdd
.
isEmpty
())
{
qt4Target
->
qt4Project
()
->
rootProjectNode
()
->
addFiles
(
UnknownFileType
,
filesToAdd
);
}
if
(
!
filesToRemove
.
isEmpty
())
{
qt4Target
->
qt4Project
()
->
rootProjectNode
()
->
removeFiles
(
UnknownFileType
,
filesToRemove
);
}
// TODO: Step 3: update the "Name" and "Exec" entries of all desktop files (name = subproject displayname, path = rhs of deployable)
return
true
;
}
void
MaemoTemplatesManager
::
handleProjectToBeRemoved
(
ProjectExplorer
::
Project
*
project
)
{
MaemoProjectMap
::
Iterator
it
=
m_maemoProjects
.
find
(
project
);
...
...
@@ -216,6 +299,23 @@ void MaemoTemplatesManager::handleProjectToBeRemoved(ProjectExplorer::Project *p
}
}
void
MaemoTemplatesManager
::
handleProFileUpdated
(
Qt4ProFileNode
*
proFileNode
)
{
for
(
MaemoProjectMap
::
ConstIterator
it
=
m_maemoProjects
.
begin
();
it
!=
m_maemoProjects
.
end
();
++
it
)
{
const
Qt4Project
*
const
project
=
qobject_cast
<
Qt4Project
*>
(
it
.
key
());
if
(
isParent
(
project
->
rootProjectNode
(),
proFileNode
))
{
// We assume here that the project configuratiion is identical for
// all Maemo targets. If that is not the case (e.g. the user has
// configured different deployment paths for Maemo5 vs. Maemo6,
// we can do things slightly wrong.
syncDesktopFiles
(
project
->
activeTarget
());
break
;
}
}
}
QString
MaemoTemplatesManager
::
version
(
const
Project
*
project
,
QString
*
error
)
const
{
...
...
@@ -431,5 +531,18 @@ Project *MaemoTemplatesManager::findProject(const QFileSystemWatcher *fsWatcher)
return
0
;
}
bool
MaemoTemplatesManager
::
isParent
(
const
ProjectNode
*
parent
,
const
ProjectNode
*
child
)
const
{
if
(
parent
==
child
)
return
true
;
const
QList
<
ProjectNode
*>
&
directChildren
=
parent
->
subProjectNodes
();
foreach
(
const
ProjectNode
*
directChild
,
directChildren
)
{
if
(
isParent
(
directChild
,
child
))
return
true
;
}
return
false
;
}
}
// namespace Internal
}
// namespace Qt4ProjectManager
src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.h
View file @
925182ff
...
...
@@ -40,11 +40,15 @@ QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher);
namespace
ProjectExplorer
{
class
Project
;
class
ProjectNode
;
class
Target
;
}
namespace
Qt4ProjectManager
{
class
Qt4Project
;
namespace
Internal
{
class
Qt4ProFileNode
;
class
MaemoTemplatesManager
:
public
QObject
{
...
...
@@ -66,8 +70,6 @@ public:
bool
setPackageManagerIcon
(
const
ProjectExplorer
::
Project
*
project
,
const
QString
&
iconFilePath
,
QString
*
error
)
const
;
static
const
QLatin1String
PackagingDirName
;
signals:
void
debianDirContentsChanged
(
const
ProjectExplorer
::
Project
*
project
);
void
changeLogChanged
(
const
ProjectExplorer
::
Project
*
project
);
...
...
@@ -75,18 +77,22 @@ signals:
private
slots
:
void
handleActiveProjectChanged
(
ProjectExplorer
::
Project
*
project
);
void
handleTarget
(
ProjectExplorer
::
Target
*
target
);
bool
handleTarget
(
ProjectExplorer
::
Target
*
target
);
void
handleDebianDirContentsChanged
();
void
handleDebianFileChanged
(
const
QString
&
filePath
);
void
handleProjectToBeRemoved
(
ProjectExplorer
::
Project
*
project
);
void
handleProFileUpdated
(
Qt4ProjectManager
::
Internal
::
Qt4ProFileNode
*
proFileNode
);
private:
explicit
MaemoTemplatesManager
(
QObject
*
parent
);
void
raiseError
(
const
QString
&
reason
);
QString
changeLogFilePath
(
const
ProjectExplorer
::
Project
*
project
)
const
;
QString
controlFilePath
(
const
ProjectExplorer
::
Project
*
project
)
const
;
bool
createTemplatesIfNecessary
(
const
ProjectExplorer
::
Target
*
target
);
bool
createDebianTemplatesIfNecessary
(
const
ProjectExplorer
::
Target
*
target
);
bool
syncDesktopFiles
(
const
ProjectExplorer
::
Target
*
target
);
ProjectExplorer
::
Project
*
findProject
(
const
QFileSystemWatcher
*
fsWatcher
)
const
;
bool
isParent
(
const
ProjectExplorer
::
ProjectNode
*
parent
,
const
ProjectExplorer
::
ProjectNode
*
child
)
const
;
QSharedPointer
<
QFile
>
openFile
(
const
QString
&
filePath
,
QIODevice
::
OpenMode
mode
,
QString
*
error
)
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment