LinuxMCE Forums

General => Developers => Topic started by: tschak909 on March 14, 2010, 03:03:35 pm

Title: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: tschak909 on March 14, 2010, 03:03:35 pm
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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: emachala on March 15, 2010, 08:17:20 am
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
Code: [Select]
/****************************************************************************
**
** 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

Code: [Select]
/****************************************************************************
**
** 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

Code: [Select]
/****************************************************************************
**
** 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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: tschak909 on March 15, 2010, 10:26:46 am
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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: emachala on March 18, 2010, 08:56:06 pm
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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: emachala on March 19, 2010, 05:08:07 pm
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?
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: tschak909 on March 19, 2010, 05:10:39 pm
Write and use the bookmarks files found in /home/user_x/bookmarks.html

-Thom
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: tschak909 on April 03, 2010, 01:50:41 am
How are you doing on this? :)

-Thom
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: emachala on April 05, 2010, 06:55:06 pm
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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: tschak909 on April 05, 2010, 06:56:34 pm
My condolences on your loss.

Thank you so much for doing this. :)

-Thom
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: apagg on May 13, 2010, 12:17:40 pm
Any progress on this?
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: tschak909 on May 23, 2010, 03:35:23 am
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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: golgoj4 on November 14, 2010, 08:07:53 am
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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: coley on November 24, 2010, 04:27:27 pm
I tried a git pull on your repo - I'm missing QtWebBrowserBase.h in Gen_Devices/
Do you have it elsewhere?

thx
-Coley.
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: golgoj4 on November 24, 2010, 08:13:08 pm
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
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: joerod on November 29, 2010, 02:46:36 pm
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...
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: golgoj4 on November 29, 2010, 05:23:08 pm
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...

I think i have most of the dce / qt stuff melded together minus one particular include. Hopefully will have something worthwhile soon. In the meantime I've been trying to document the process in a more cohesive manner http://wiki.linuxmce.org/index.php/C%2B%2B_Project.

-golgoj4
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: joerod on February 12, 2011, 04:46:36 am
any news on this?
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: golgoj4 on June 05, 2011, 03:35:42 am
http://www.youtube.com/watch?v=H-LECJJ8ae0
Done
*DCE implementation
*forward, back, reload, goto url

todo
*designer ui
*bookmarks
*Q/A
*Experimental features
*flash

stay tuned.
golgoj4
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: tschak909 on June 05, 2011, 02:00:02 pm
Fantastic, bro. :)

You're already to a point where you can hook it up in the General Info Plugin. (Literally grep for Mozilla.sh (if I remember right, it's an app server call), and there is a bit of code that grabs the window ID from the entry in the database.)

Then Orbiter can swallow the window (You'll see a call to CMD_Select_Active_Window that brings the web window to front.) Perhaps the window can minimize when done...

-Thom
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: posde on June 05, 2011, 08:00:44 pm
golgoj4,

great that you've come so far. Please keep in mind, that we will not any new features now. You can continue with what you do, but do NOT touch any of the existing code for integration purposes.

We will not add any new feature until LinuxMCE 810 is released, or Ubuntu 1110 has been released, whatever comes first.
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: golgoj4 on September 02, 2011, 09:36:05 pm
come on release time!!! daddy wants to watch some adult swim!

 :D

Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: joerod on November 29, 2011, 10:15:17 pm
this would be so awesome!
Title: Re: Programming Exercise: Using QT and WebKit to produce a micro-browser.
Post by: joerod on June 04, 2012, 07:37:46 am
Any update on this?