News:

Rule #1 - Be Patient - Rule #2 - Don't ask when, if you don't contribute - Rule #3 - You have coding skills - LinuxMCE's small brother is available: http://www.agocontrol.com

Main Menu

Programming Exercise: Using QT and WebKit to produce a micro-browser.

Started by tschak909, March 14, 2010, 03:03:35 PM

Previous topic - Next topic

tschak909

Firefox should be replaced.

QT and QWebView can be used to produce a working micro-browser, running in a thread of a DCE device.

Pay attention to the above statement, what I am saying is to build a DCE device, and attach a thread to it to handle a UI.

Examples of this, would be SimplePhone, LMCE_Launch_Manager...

FlickCharm or some form of kinetic scrolling should be implemented.

Should have the ability to add bookmarks to the main bookmarks menu.
Should have the ability to be controlled by DCE commands for:

* Load URL
* Forward
* Back
* Add Bookmark

and should emit DCE events for:

* Page Loading
* Page Loaded

This would allow an orbiter UI to be built, that could update the currently shown address, and show progress, and actually be able to do the commands above.

There is no visible UI except the beowser view.
There is no address bar
There is no status bar
If you add them, I will smack you, and tell you to remove them.

The UI will be provided by Orbiter.

Come on, fellas. This can be done in roughly 200 lines of code in Qt.
Somebody grow a sack and do it.

or is this another thing I will have to write to prove a point? :)

-Thom

emachala

Hi All, would like to start trying to contribute more... And learn more about the frameworks and linuxmce´s insides.

So this is what Ive gotten so far... Not sure if im still on the right track but ive gotten the browser down to just that... Not sure where i should go from here?

main.cpp

/****************************************************************************
**
** lmcebrowser beta2 0810  3/15/10
**
****************************************************************************/

#include <QtGui>
#include "mainwindow.h"

int main(int argc, char * argv[])
{
    QApplication app(argc, argv);
    MainWindow *browser = new MainWindow;
    browser->show();
    return app.exec();
}


mainwindow.cpp


/****************************************************************************
**
** lmcebrowser beta 2 0810
**
****************************************************************************/

#include <QtGui>
#include <QtWebKit>
#include "mainwindow.h"


MainWindow::MainWindow()
{
     progress = 0;

     QFile file;
     file.setFileName(":/jquery.min.js");
     file.open(QIODevice::ReadOnly);
     jQuery = file.readAll();
     file.close();

     view = new QWebView(this);
     view->load(QUrl("http://wiki.linuxmce.com"));
     connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
     connect(view, SIGNAL(titleChanged(const QString&)), SLOT(adjustTitle()));
     connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int)));
     connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));



     setCentralWidget(view);
}



void MainWindow::adjustTitle()
{
     if (progress <= 0 || progress >= 100)
         setWindowTitle(view->title());
     else
         setWindowTitle(QString("%1 (%2%)").arg(view->title()).arg(progress));
}

void MainWindow::setProgress(int p)
{
     progress = p;
     adjustTitle();
}

void MainWindow::finishLoading(bool)
{
     progress = 100;
     adjustTitle();
     view->page()->mainFrame()->evaluateJavaScript(jQuery);
}


mainwindow.h


/****************************************************************************
**
** lmcebrowser 3/15/10
**
****************************************************************************/

#include <QtGui>

class QWebView;
class QLineEdit;

class MainWindow : public QMainWindow
{
     Q_OBJECT

public:
     MainWindow();

protected slots:


     void adjustTitle();
     void setProgress(int p);
     void finishLoading(bool);


private:
     QString jQuery;
     QWebView *view;
     QLineEdit *locationEdit;
     int progress;
};


Really will load so much faster that other browsers... was a really good idea.... not sure how im supposed to prep this to be able to to be controlled by DCE commands... working on bookmarking now  Am I on the right track?  heres a SS of the browser
-emac

-----------------------------
[url="http://wiki.linuxmce.org/index.php/User:Emachala"]http://wiki.linuxmce.org/index.php/User:Emachala[/url]

tschak909

Very nice.

The trick now, is a bit more interesting...

You need to get a copy of the LinuxMCE build tree available, if you do not already have it. This can be done without a full builder so basically, you can check out the code from the LinuxMCE-0810 branch (all you really need is src), copy /usr/pluto/lib into src/lib, install the pluto-sql2cpp and pluto-dcegen packages, and add the following environment variables to your .profile SNR_CPPFLAGS="-DKDE-LMCE" SNR_LDFLAGS=" " ... You can then:

* do an sqlcvs update of the DCE repository from the web admin to get up to date.
* Create a device template in the web admin, describing the web browser, its commands, and its events.
* Run DCEGen with -d xxxx where xxxx is the device template # that it gave you when you created the template.

you will now have a directory named the same as your template, with spaces replaced by underscores.

Inside this, you will have the relevant code for the DCE portion of the browser... now... here's the trick

* You need to fold the Qt stuff over, replace the main.cpp here with Qt's main.cpp,

This will make the main thread the Qt program.

* You need to add the DCE bits to the qmake project file, including your base files in src/Gen_Devices (adding include paths for .. and a few other places is probably a good idea.)

* You need to make the main.cpp initialize the DCE code. This involves literally calling its GetConfig method, and then calling run. The good news is, once you do this, it will spawn threads it needs automatically.

* You need to make a global variable that you can pass between threads, so you can communicate between the DCE thread and the GUI thread to call things in the DCE thread for events, and so DCE thread can call things over in the Qt thread for events.

look at src/lmce_launch_manager_old for an example of how to meld a GUI app together with DCE. This is the old LMCE Launch Manager GUI, and implements exactly these patterns.

Once you have this, you'll have a working DCE controllable web browser that you can test by manually adding to a system in the web admin, and sending commands to it via "Send Command" in the web admin. or via MessageSend.

(yes, I have deliberately left some things unsaid, this is an exercise.) :)

-Thom

emachala

Heya... Been Feeling very crappy last few days... much better now... sucks being sick on your birthday... printed up template code and was mulling over during my down time since this is my first time digging into mce src... quick question on web bookmarks... Currently i have my device template  setup with Browser Commands...  Goto_Url#1076 #Go_Back#1079 #Go_Forward#1078 #Web_Bookmark#1080... Web_Bookmark is a #193 URL (String) Parameter... and it will take current url ...will adding this bookmark to computing bookmarks menu be taken care by this command later or do i need to do this now.. adding url string somewhere?.. to bookmark storage location ... will be working on this next few days and getting it all down right...

QT is really cool... should be able to do some other cool stuff with this...

Emachala
-emac

-----------------------------
[url="http://wiki.linuxmce.org/index.php/User:Emachala"]http://wiki.linuxmce.org/index.php/User:Emachala[/url]

emachala

KK.. never really used bookmarks  see it now...  i will make current QUrl value and write it to file /home/public/bookmarks.html  in same format as entries..  is this okay?  It says the file will be over written  is this by firefox?
-emac

-----------------------------
[url="http://wiki.linuxmce.org/index.php/User:Emachala"]http://wiki.linuxmce.org/index.php/User:Emachala[/url]

tschak909

Write and use the bookmarks files found in /home/user_x/bookmarks.html

-Thom

tschak909


emachala

Testing my build now... my grandfather on my father's side passed... so was away for a bit in FL, will post my build source soon for others to test and overview... looking good.

Eric
-emac

-----------------------------
[url="http://wiki.linuxmce.org/index.php/User:Emachala"]http://wiki.linuxmce.org/index.php/User:Emachala[/url]

tschak909

My condolences on your loss.

Thank you so much for doing this. :)

-Thom


tschak909

bump, emachala, if you're not going to work on this any further, could you please post code so one of us could finish it?

-Thom

golgoj4

going to see how far i can get with this. he posted most of the qt stuff so its a matter of trying to pick up the dce integration.

sounds so easy hehe...

golgoj4
Linuxmce - Where everyone is never wrong, but we are always behind xbmc in the media / ui department.

coley

I tried a git pull on your repo - I'm missing QtWebBrowserBase.h in Gen_Devices/
Do you have it elsewhere?

thx
-Coley.
~ 12.04 Alpha: [url="http://linuxmce.iptp.org/snapshots"]http://linuxmce.iptp.org/snapshots[/url]
~ 10.04 Final: [url="http://linuxmce.iptp.org/release/LinuxMCE-1004-final.iso"]http://linuxmce.iptp.org/release/LinuxMCE-1004-final.iso[/url]
~ My setup: [url="http://wiki.linuxmce.org/index.php/User:Coley"]http://wiki.linuxmce.org/index.php/User:Coley[/url]

golgoj4

Odd that should have been there...Ill be taking a look at this today but I cant promise any speed as its Turkey Day here tomorrow and im being required to be useful and junk. :) I appreciate the second set of eyes and ill look into why its not there.

-golgoj4
Linuxmce - Where everyone is never wrong, but we are always behind xbmc in the media / ui department.

joerod

Any updates on this? It sounds really cool and seems like it has been something planned for a long time...

I also like how most of the process for developing the feature has been documented it has given me a little more insight on how apps are integrated into the dce process...