用dillo内核做的一个浏览器

由于qt提供了良好的嵌入其它窗口的功能,如QX11EmbedContainer类就可以将其它窗口捕获,并使之成为自己的一部分。使用浏览器dillo的内核,做了一个适合普通用户的浏览器界面。浏览器dillo是一个GTK程序,有两种方法将它嵌入qt界面:

a)      先得到gtk窗口的id,然后将这个id传递给qt进程的QX11EmbedContainer对象,再调用embedClient(WId)函数将gtk窗口加到qt里面. 得到gtk窗口id使用函数 GDK_WINDOW_XWINDOW (GTK_WIDGET (window1)->window);

b)      首先在我们的界面internetpage中新建一个widget,winId()函数得到它的窗口id,然后在打开浏览器dillo进程的命令中使用-x ****(得到的id),即可,如list << "dillo" << "-f" << "-g 765x540" << "-x" << temp <<"/r"-g 765x540是指定窗口的初始大小。

由于浏览器dillo提供了-x参数,只需给它指定一个窗口ID就可以了,所以我们用了第二种方法。

1.     界面设计

1)        在界面上提供了一个软键盘,专们用于网址的输入,所以去掉了其它特殊的按键。输入方法和使用键盘输入类似,输入完毕,点击Enter键即可登录互联网,浏览网页。

2)        浏览器增加了最近浏览功能,当用户输入网址时,系统会自动搜索用户浏览过的网页地址,并把与输入匹配的所有网址读列出来,用户可以通过选择列出来的网址打开网页,就像使用IE浏览器一样的的效果。

3)        最近浏览功能的实现

用户访问过的网址存在history.txt文件中,在输入网页的过程中,每输入一个字符,都会把当前地址栏的内容与原来存在文件的内容比较,并列出与当前输入匹配的网页地址。当用户浏览一个history.txt文件中不存在的网址时,该地址会自动记录到history.txt文件中。

 

截图:

 

 

实现代码:

//internetpage.h

class InternetPage : public QWidget//互联网类的声明

{   Q_OBJECT

public:

InternetPage(QWidget *parent = 0);

QFrame *frame;

My_GroupBox *internetGroup;

My_LineEdit *lineEdit;

void web();

void showweb();

public slots:                  

void keyboard();

void showkeyboard();

void enter();

void add();

void select(QListWidgetItem *);

private:

unsigned long wid;

QProcess *browser;

QPushButton *enterbutton;

QListWidget *weblist;

QFile *file;

QList<QString> fitweb;

QPushButton *button1;

QPushButton *button2;

QPushButton *button3;

QPushButton *button4;

QPushButton *button5;

QPushButton *button6;

QPushButton *button7;

QPushButton *button8;

QPushButton *button9;

QPushButton *button0;

QPushButton *buttonQ;

QPushButton *buttonW;

QPushButton *buttonE;

QPushButton *buttonR;

QPushButton *buttonT;

QPushButton *buttonY;

QPushButton *buttonU;

               QPushButton *buttonI;

               QPushButton *buttonO;

               QPushButton *buttonP;

 

               QPushButton *buttonA;

               QPushButton *buttonS;

               QPushButton *buttonD;

               QPushButton *buttonF;

               QPushButton *buttonG;

               QPushButton *buttonH;

               QPushButton *buttonJ;

               QPushButton *buttonK;

               QPushButton *buttonL;

               QPushButton *buttonColon;

 

               QPushButton *buttonZ;

               QPushButton *buttonX;

               QPushButton *buttonC;

               QPushButton *buttonV;

               QPushButton *buttonB;

               QPushButton *buttonN;

               QPushButton *buttonM;

               QPushButton *buttonDot;

               QPushButton *buttonXie;

 

               QPushButton *buttonEnter;

              

               QPushButton *buttondel;

};

 

 

//internetpage.cpp

InternetPage::InternetPage(QWidget *parent)//互联网类的定义

    : QWidget(parent)

{

           internetGroup = new My_GroupBox(tr(""));

           connect(internetGroup, SIGNAL(mousepressed(QMouseEvent*)), parent, SLOT(mousePressEvent(QMouseEvent*)));

 

           QLabel *address = new QLabel("Address",internetGroup);

           address->setGeometry(QRect(1,0,60,30));

           lineEdit = new My_LineEdit(internetGroup);

           lineEdit->setGeometry(QRect(66,0,699,30));            

               connect(lineEdit,SIGNAL(mousepressed()),this,SLOT(showkeyboard())); 

 

 

   

           QX11EmbedWidget *contain = new QX11EmbedWidget(internetGroup);

           contain->setGeometry(0,35,800,560);

           wid = contain->winId();

           web();//显示网页内容

               keyboard();//构造一个键盘

               file = new QFile("history.txt");//创建一个文件,存放最近访问过的网页

               connect(weblist, SIGNAL(itemPressed(QListWidgetItem *)), this,SLOT(select(QListWidgetItem *)));

 

 

           QVBoxLayout *mainLayout = new QVBoxLayout;

           mainLayout->addWidget(internetGroup);

           mainLayout->addSpacing(12);

           mainLayout->addStretch(1);

           setLayout(mainLayout);

           internetGroup->setMinimumSize(600,560);

}

 

//打开浏览器,并记录新输入的网页地址

void InternetPage::showweb()

{

               int flag;

       browser->kill();

               QStringList list;

             QString temp;

               temp.setNum(wid);//获得frameid,并转化为QString型的数据

 

               QString address;

               address = lineEdit->text();

              

               //file = new QFile("history.txt");

               if (!file->open(QIODevice::ReadWrite | QIODevice::Text))

                  printf("open file history to read1 error.......");

               QTextStream in(file);

               while (!in.atEnd()) {

                    QString line = in.readLine();

                    if(QString::compare(address,line)==0)

                       flag=1;         

               }

               printf("the flag is %d/n....",flag);

               file->close();

               if (!file->open(QIODevice::Append | QIODevice::Text))

                  printf("open file history to write error.......");

               if(flag!=1)

               {QTextStream out(file);

                out<<address<<"/n";

                }

              

               list << "dillo" << "-f" << "-g 765x540" << "-x" << temp << address<<"/r";//全屏,初始大小,窗口位置

               QString str = list.join(" ");

             

               browser = new QProcess();

               //char *wedsite = str.toStdString().c_str()

               browser->start(str.toStdString().c_str(),QIODevice::ReadWrite);

               file->close();

}

//完成浏览网址的匹配。

void InternetPage::add()

{

               weblist->clear();

               if (!file->open(QIODevice::ReadWrite | QIODevice::Text))

                  printf("open file history to read error.......");

               QTextStream in(file);

               QString getText;

               getText = lineEdit->text();

               while (!in.atEnd()) {

                    QString line = in.readLine();

                    if(line.contains(getText,Qt::CaseInsensitive))

                    {

                     fitweb.append(line);

                    QListWidgetItem *item = new QListWidgetItem(line);

                    item->setFont(QFont("Times",18,QFont::Bold));                

                    //item->setText(file.section("/", -1));                 

                    item->setTextColor(QColor(225,0,225));           

              

                    weblist->insertItem(fitweb.size(),item);}

               }

               file->close();   

                                        

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值