PATCH - add FBReader as document handler for the filemanager in maemo2

5 views
Skip to first unread message

danny...@gmail.com

unread,
Oct 18, 2006, 4:24:28 PM10/18/06
to FBReader
Hi,

I patched FBReader to make it handle text/html, text/plain and
application/xhtml+xml documents from the file manager.
Seems to work pretty well, BUT I'm still missing a way to present the
window after it is done loading.

(The window management system of the device is one-window-at-a-time)

The problem is like that:

Steps:
- launch file manager (full screen)
- click on a text/plain file
- fbreader starts (full screen, completely obscuring file manager) and
opens document
- switch to filemanager (full screen, completely obscuring fbreader)
- click on another text/plain file
- seemingly nothing happens
- somewhen later switch back to fbreader
- ah, it worked :)

So I guess we need a reader->present() or something, yes?

cheers,
Danny

diff -upr orig/fbreader-0.7.4h/fbreader/maemo/FBReader.desktop.in
fbreader-0.7.4h/fbreader/maemo/FBReader.desktop.in
--- orig/fbreader-0.7.4h/fbreader/maemo/FBReader.desktop.in 2006-08-10
02:29:02.000000000 +0200
+++ fbreader-0.7.4h/fbreader/maemo/FBReader.desktop.in 2006-10-18
21:10:45.000000000 +0200
@@ -9,3 +9,5 @@ X-Window-Icon=FBReader
X-Window-Icon-Dimmed=FBReader
X-Osso-Service=FBReader
X-Osso-Type=application/x-executable
+MimeType=text/plain;text/html;application/xhtml+xml;
+
diff -upr orig/fbreader-0.7.4h/fbreader/maemo/FBReader.postinst
fbreader-0.7.4h/fbreader/maemo/FBReader.postinst
--- orig/fbreader-0.7.4h/fbreader/maemo/FBReader.postinst 2006-08-10
02:29:02.000000000 +0200
+++ fbreader-0.7.4h/fbreader/maemo/FBReader.postinst 2006-10-18
22:04:29.000000000 +0200
@@ -5,6 +5,8 @@ then
/usr/bin/gtk-update-icon-cache -f /usr/share/icons/hicolor
fi

+/usr/bin/update-mime-database /usr/share/mime
+
if [ "$1" = "configure" -a -z "$2" -a -x
/usr/bin/maemo-select-menu-location ]
then
/usr/bin/maemo-select-menu-location FBReader.desktop
diff -upr orig/fbreader-0.7.4h/fbreader/maemo/maemo2/main.cpp
fbreader-0.7.4h/fbreader/maemo/maemo2/main.cpp
--- orig/fbreader-0.7.4h/fbreader/maemo/maemo2/main.cpp 2006-08-10
02:29:02.000000000 +0200
+++ fbreader-0.7.4h/fbreader/maemo/maemo2/main.cpp 2006-10-18
22:07:55.000000000 +0200
@@ -30,10 +30,70 @@
#include <maemo-maemo2/GtkApplicationWindow.h>

#include "../../common/fbreader/FBReader.h"
+#include "../../common/collection/BookList.h"
+#include "../../common/description/BookDescription.h"
+#include <libosso.h>
+
+static char const* find_first_existing_argument(int argc, char*
argv[])
+{
+ int i;
+
+ for (i = 0; i < argc; ++i) {
+ if (argv[i] == NULL) {
+ continue;
+ }
+
+ if (g_str_equal(argv[i], "--")) { /* end-of-options */
+ continue;
+ }
+
+ return argv[i];
+ }
+
+ return NULL;
+}
+
+static FBReader* reader;
+
+static void document_open_callback(gpointer data, int argc, char*
argv[])
+{
+ char* document_path;
+ char const* document_url;
+ document_url = find_first_existing_argument(argc, argv);
+ if (document_url == NULL) {
+ g_warning("found no document to open");
+ return;
+ }
+ document_path = g_filename_from_uri(document_url, NULL
/*&document_host*/, NULL);
+ if (document_path == NULL) {
+ g_warning("could not find path to document");
+ return;
+ }
+
+ BookDescriptionPtr description =
BookDescription::create(document_path);
+
+ reader->openBook(description);
+ g_free(document_path);
+ reader->refreshWindow();
+ //BookList().addFileName(document_path);
+ //reader->setMode(BOOK_TEXT_MODE);
+ /* BUG: window is not presented */
+}
+
+static osso_context_t* osso_context;

int main(int argc, char **argv) {
+ char const* document_path;
+
gtk_init(&argc, &argv);

+ osso_context = osso_initialize("FBReader", "2.0", FALSE, NULL);
+ if (osso_context != NULL) {
+ osso_mime_set_cb(osso_context, document_open_callback, NULL);
+ } else {
+ g_warning("could not register document handler service");
+ }
+
ZLUnixFSManager::createInstance();
ZLGtkTimeManager::createInstance();
GtkDialogManager::createInstance();
@@ -41,8 +101,9 @@ int main(int argc, char **argv) {

((GtkDialogManager&)GtkDialogManager::instance()).setPixmapPath(GtkApplicationWindow::ImageDirectory);
GtkDeviceInfo::createInstance();

+ document_path = find_first_existing_argument(argc - 1, &argv[1]);
// MSS: use the first argument that gtk did not consume
- FBReader *reader = new FBReader(new GtkPaintContext(), argc == 1 ?
std::string() : argv[1]);
+ reader = new FBReader(new GtkPaintContext(), document_path != NULL ?
document_path : std::string());
ZLDialogManager::instance().createApplicationWindow(reader);
reader->initWindow();
gtk_main();
diff -upr
orig/fbreader-0.7.4h/zlibrary/abstract/application/ZLApplication.cpp
fbreader-0.7.4h/zlibrary/abstract/application/ZLApplication.cpp
---
orig/fbreader-0.7.4h/zlibrary/abstract/application/ZLApplication.cpp 2006-08-10
02:29:02.000000000 +0200
+++
fbreader-0.7.4h/zlibrary/abstract/application/ZLApplication.cpp 2006-10-18
21:59:42.000000000 +0200
@@ -111,6 +111,7 @@ void ZLApplication::refreshWindow() {
if (myWindow != 0) {
myWindow->refresh();
}
+ resetWindowCaption();
}

void ZLApplication::Action::checkAndRun() {
diff -upr
orig/fbreader-0.7.4h/zlibrary/maemo/application-maemo2/GtkApplicationWindow.cpp
fbreader-0.7.4h/zlibrary/maemo/application-maemo2/GtkApplicationWindow.cpp
---
orig/fbreader-0.7.4h/zlibrary/maemo/application-maemo2/GtkApplicationWindow.cpp 2006-08-10
02:29:02.000000000 +0200
+++
fbreader-0.7.4h/zlibrary/maemo/application-maemo2/GtkApplicationWindow.cpp 2006-10-18
22:03:12.000000000 +0200
@@ -80,9 +80,9 @@ static void mousePressed(GtkWidget*, Gdk

GtkApplicationWindow::GtkApplicationWindow(ZLApplication *application)
: ZLApplicationWindow(application) {
myProgram = HILDON_PROGRAM(hildon_program_get_instance());
- g_set_application_name("");
+ g_set_application_name(ZLApplication::ApplicationName().c_str());

- osso_initialize(ZLApplication::ApplicationName().c_str(), "0.0",
false, 0);
+ /* osso_initialize(ZLApplication::ApplicationName().c_str(), "0.0",
false, 0); waaay too buried */

myWindow = HILDON_WINDOW(hildon_window_new());

Nur in fbreader-0.7.4h/zlibrary/unix/time: ZLUnixTime.o.

Victor Wagner

unread,
Oct 19, 2006, 4:50:39 AM10/19/06
to fbre...@googlegroups.com
On 2006.10.18 at 13:24:28 -0700, danny...@gmail.com wrote:

>
> Hi,
>
> I patched FBReader to make it handle text/html, text/plain and
> application/xhtml+xml documents from the file manager.
> Seems to work pretty well, BUT I'm still missing a way to present the
> window after it is done loading.

Interesting idea. It would be useful for desktop version too.

>

geometer

unread,
Nov 7, 2006, 12:09:23 PM11/7/06
to FBReader
Hello,

thank you for the patch. It's not a problem to add your
document_open_callback to "official" fbreader code, but I'm not sure
about updating mime database. I'm not sure that fbreader is the best
choice for html files for ALL users.

-- Nikolay Pultsin

danny...@gmail.com

unread,
Nov 7, 2006, 12:45:56 PM11/7/06
to FBReader
As far as I understand the standard, a "MimeType" key doesn't mean that
users are _required_ to use that application to open files of said mime
type.

The Standard said:

http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s07.html

"The MimeType key is used to indicate the MIME Types that an
application knows how to handle. It is expected that for some
applications this list could become long. An application is expected to
be able to reasonably open files of these types using the command
listed in the Exec key.

There should be no priority for MIME Types in this field, or any form
of priority in the desktop file. Priority for applications is handled
external to the .desktop files. "

It is a bit vague on it but I take it to mean
"if your app can do mimetype x AT ALL, say so in the desktop file".

Which application really _is_ used by the desktop environment is a
separate concern and not handled by that.

As for the update-mime-database call, one is expected to call that
after installing a desktop file (ah, and "update-desktop-database" as
well).

But you are right that the real world probably took the easy way out
and ignored that part of the standard :( sigh...

MishaS

unread,
Nov 7, 2006, 5:04:58 PM11/7/06
to FBReader
Hi Danny

I believe there is a complementary file that describes other things
related to mime in maemo platform. However I could not find it as it
is. :( I'll check it and see what other information is available... :(

--
Misha

MishaS

unread,
Nov 8, 2006, 7:22:04 AM11/8/06
to FBReader
Hi Danny

I checked internally and they pointed me to

http://maemo.org/platform/docs/tutorials/Maemo_tutorial.html#mime

It's a part of maemo tutorial. I hope this helps.

--
Misha

Reply all
Reply to author
Forward
0 new messages