Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Itinerary
Commits
fd6719ec
Commit
fd6719ec
authored
Feb 24, 2018
by
Volker Krause
Browse files
Resolve Android content: URLs
This allows opening boarding passes from other apps, such as the file manager.
parent
8c8afd67
Changes
5
Hide whitespace changes
Inline
Side-by-side
add_license.sh
View file @
fd6719ec
#!/bin/bash
find
"
$@
"
-name
'*.h'
-o
-name
'*.cpp'
-o
-name
'*.qml'
|
grep
-v
/3rdparty/ |
while
read
FILE
;
do
find
"
$@
"
-name
'*.h'
-o
-name
'*.cpp'
-o
-name
'*.qml'
-o
-name
'*.java'
|
grep
-v
/3rdparty/ |
while
read
FILE
;
do
if
grep
-qiE
"Copyright
\(
C
\)
[0-9, -]{4,} "
"
$FILE
"
;
then continue
;
fi
thisfile
=
`
basename
$FILE
`
authorName
=
`
git config user.name
`
...
...
src/app/AndroidManifest.xml
View file @
fd6719ec
...
...
@@ -6,7 +6,7 @@
android:installLocation=
"auto"
>
<application
android:name=
"org.qtproject.qt5.android.bindings.QtApplication"
android:label=
"KDE Itinerary"
android:icon=
"@drawable/icon"
>
<activity
android:configChanges=
"orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation"
android:name=
"org.
qtproject.qt5.android.bindings.Qt
Activity"
android:name=
"org.
kde.itinerary.
Activity"
android:label=
"KDE Itinerary"
android:windowSoftInputMode=
"adjustResize"
android:launchMode=
"singleTop"
>
...
...
src/app/CMakeLists.txt
View file @
fd6719ec
add_library
(
itinerary
STATIC
set
(
itinerary
_srcs
pkpassmanager.cpp
timelinemodel.cpp
)
ecm_qt_declare_logging_category
(
itinerary_srcs
HEADER logging.h
IDENTIFIER Log
CATEGORY_NAME org.kde.itinerary
)
add_library
(
itinerary STATIC
${
itinerary_srcs
}
)
target_link_libraries
(
itinerary PUBLIC
KPkPass
)
...
...
src/app/main.cpp
View file @
fd6719ec
...
...
@@ -16,6 +16,7 @@
*/
#include
"itinerary_version.h"
#include
"logging.h"
#include
"pkpassmanager.h"
#include
"timelinemodel.h"
...
...
@@ -33,9 +34,43 @@
#endif
#include
<QCommandLineParser>
#include
<QDebug>
#include
<QGuiApplication>
#include
<QIcon>
void
handleViewIntent
(
PkPassManager
*
passMgr
)
{
#ifdef Q_OS_ANDROID
// handle opened files
const
auto
activity
=
QtAndroid
::
androidActivity
();
if
(
!
activity
.
isValid
())
return
;
const
auto
intent
=
activity
.
callObjectMethod
(
"getIntent"
,
"()Landroid/content/Intent;"
);
if
(
!
intent
.
isValid
())
return
;
const
auto
uri
=
intent
.
callObjectMethod
(
"getData"
,
"()Landroid/net/Uri;"
);
if
(
!
uri
.
isValid
())
return
;
const
auto
scheme
=
uri
.
callObjectMethod
(
"getScheme"
,
"()Ljava/lang/String;"
);
if
(
scheme
.
toString
()
==
QLatin1String
(
"content"
))
{
const
auto
tmpFile
=
activity
.
callObjectMethod
(
"receiveContent"
,
"(Landroid/net/Uri;)Ljava/lang/String;"
,
uri
.
object
<
jobject
>
());
passMgr
->
importPass
(
QUrl
::
fromLocalFile
(
tmpFile
.
toString
()));
}
else
if
(
scheme
.
toString
()
==
QLatin1String
(
"file"
))
{
const
auto
uriStr
=
uri
.
callObjectMethod
(
"toString"
,
"()Ljava/lang/String;"
);
passMgr
->
importPass
(
QUrl
(
uriStr
.
toString
()));
}
else
{
const
auto
uriStr
=
uri
.
callObjectMethod
(
"toString"
,
"()Ljava/lang/String;"
);
qCWarning
(
Log
)
<<
"Unknown intent URI:"
<<
uriStr
.
toString
();
}
#else
Q_UNUSED
(
passMgr
);
#endif
}
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
...
...
@@ -73,21 +108,7 @@ int main(int argc, char **argv)
for
(
const
auto
&
file
:
parser
.
positionalArguments
())
passMgr
.
importPass
(
QUrl
::
fromLocalFile
(
file
));
#ifdef Q_OS_ANDROID
// handle opened files
const
auto
activity
=
QtAndroid
::
androidActivity
();
if
(
activity
.
isValid
())
{
const
auto
intent
=
activity
.
callObjectMethod
(
"getIntent"
,
"()Landroid/content/Intent;"
);
if
(
intent
.
isValid
())
{
const
auto
data
=
intent
.
callObjectMethod
(
"getDataString"
,
"()Ljava/lang/String;"
);
if
(
data
.
isValid
())
{
// TODO handle content:// urls
passMgr
.
importPass
(
QUrl
(
data
.
toString
()));
}
}
}
#endif
handleViewIntent
(
&
passMgr
);
return
app
.
exec
();
}
src/app/src/org/kde/itinerary/Activity.java
0 → 100644
View file @
fd6719ec
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
org.kde.itinerary
;
import
org.qtproject.qt5.android.bindings.QtActivity
;
import
android.content.ContentResolver
;
import
android.net.Uri
;
import
android.util.Log
;
import
java.io.*
;
public
class
Activity
extends
QtActivity
{
private
static
final
String
TAG
=
"org.kde.itinerary"
;
public
String
receiveContent
(
Uri
uri
)
{
ContentResolver
resolver
=
getContentResolver
();
File
tempFile
=
new
File
(
getCacheDir
(),
"content"
);
// TODO use random name
try
{
InputStream
is
=
resolver
.
openInputStream
(
uri
);
tempFile
.
createNewFile
();
FileOutputStream
os
=
new
FileOutputStream
(
tempFile
);
while
(
true
)
{
byte
[]
buffer
=
new
byte
[
4096
];
int
size
=
is
.
read
(
buffer
,
0
,
4096
);
if
(
size
<
0
)
{
break
;
}
os
.
write
(
buffer
,
0
,
size
);
}
os
.
close
();
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
e
.
toString
());
return
""
;
}
return
tempFile
.
toString
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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