bookmarksengine/browsercontentdll/src/browsercontentdll.cpp
author hgs
Fri, 15 Oct 2010 17:29:22 -0400
changeset 15 5ea3798f1248
parent 12 d26902edeef5
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
*
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     5
* This program is free software: you can redistribute it and/or modify
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     6
* it under the terms of the GNU Lesser General Public License as published by
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     7
* the Free Software Foundation, version 2.1 of the License.
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     8
* 
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     9
* This program is distributed in the hope that it will be useful,
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    12
* GNU Lesser General Public License for more details.
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    14
* You should have received a copy of the GNU Lesser General Public License
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    15
* along with this program.  If not, 
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    16
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
*
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    18
* Description:
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
*
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
*/
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include<QString>
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#include<browsercontentdll.h>
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include<QSqlDatabase>
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
#include<QSqlQuery>
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include<QSqlError>
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include<QDebug>
6
hgs
parents: 3
diff changeset
    28
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
const QString dbLocation="browserContent.db";
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
6
hgs
parents: 3
diff changeset
    31
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    32
class BrowserContentPrivate {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
BOOKMARKSCLIENT_PUBLIC(BrowserContent)
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
public:
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
    ~BrowserContentPrivate();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
    QString m_connectionName;
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    37
};
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
 * Description: Constructor of BrowserContentPrivate
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
 ================================================================*/
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
BrowserContentPrivate::~BrowserContentPrivate()
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    43
{
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    45
}
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
 * Description: Constructor of BrowserContent
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
 ================================================================*/
15
hgs
parents: 12
diff changeset
    50
BrowserContent::BrowserContent(QString aClientName)  //used for test purposes only
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    51
{
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
    BOOKMARKSCLIENT_INITIALIZE(BrowserContent);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
    
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
    priv->m_connectionName=aClientName;
15
hgs
parents: 12
diff changeset
    55
    createDatabase(dbLocation);
hgs
parents: 12
diff changeset
    56
}
hgs
parents: 12
diff changeset
    57
hgs
parents: 12
diff changeset
    58
BrowserContent::BrowserContent(QString aClientName, QString databaseName)
hgs
parents: 12
diff changeset
    59
{
hgs
parents: 12
diff changeset
    60
    BOOKMARKSCLIENT_INITIALIZE(BrowserContent);
hgs
parents: 12
diff changeset
    61
hgs
parents: 12
diff changeset
    62
    priv->m_connectionName=aClientName;
hgs
parents: 12
diff changeset
    63
    createDatabase(databaseName);
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    64
}
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
 * Description: creates the database
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
 ================================================================*/
15
hgs
parents: 12
diff changeset
    69
int BrowserContent::createDatabase(QString name)
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    70
{
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
    
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
    QSqlDatabase sqlDB = QSqlDatabase::addDatabase("QSQLITE", priv->m_connectionName);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
    sqlDB.setHostName("Simulator");
15
hgs
parents: 12
diff changeset
    75
    sqlDB.setDatabaseName(name);
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
    if (!sqlDB.open())
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
        return -1;
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
    QSqlError error;
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    80
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    81
    //Check if the table exists, create table only when it's empty 
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    82
    QStringList tablelist = sqlDB.tables(QSql::Tables);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    83
    if (tablelist.count() == 0) {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    84
        QSqlQuery query(sqlDB);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
        query.exec(
3
hgs
parents: 2
diff changeset
    86
           "CREATE TABLE BookMarkTable (title VARCHAR NOT NULL,url VARCHAR,adate VARCHAR,tags VARCHAR,rowindex INTEGER, domain VARCHAR,CONSTRAINT pk_BookMarkTable PRIMARY KEY(title))");
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
           error=query.lastError();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    88
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    89
        if (error.type() == QSqlError::NoError) {
3
hgs
parents: 2
diff changeset
    90
            query.exec("CREATE TABLE HistoryTable (rowindex INTEGER  PRIMARY KEY, pageTitle VARCHAR NOT NULL,url VARCHAR,domain VARCHAR, timestamp int)");
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
          error=query.lastError();
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    92
        }                        
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
    }
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
      
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
    if (error.type() == QSqlError::NoError) {
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    96
          return ErrNone;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    97
     } else {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    98
          return ErrGeneral;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    99
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   100
}
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
 
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
 * Description: Destrcutor of the BookmarksClientSide
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   105
 ================================================================*/
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   106
BrowserContent::~BrowserContent()
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
    {
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
    }
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   110
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
 * Description: fetches Allbookmarks From database
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   114
 ================================================================*/
3
hgs
parents: 2
diff changeset
   115
QList<BookmarkLeaf*> BrowserContent::fetchAllBookmarks()
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   116
{
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   117
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
    QList<BookmarkLeaf*> nodeslist;
15
hgs
parents: 12
diff changeset
   120
        
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   121
    bool dbopen = db.isOpen();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
    bool ok;
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   123
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   124
    if (dbopen) {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   125
        QSqlQuery query(db);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   126
        query.prepare("SELECT title,url,adate,tags,rowindex FROM BookMarkTable ORDER BY rowindex");
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   127
        query.exec();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
        QSqlError error = query.lastError();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   130
        while (query.next()) {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
            QString title = query.value(0).toString();
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   132
            if(title.contains("'", Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   133
                title.replace(QString("'"), QString("&#39"));
3
hgs
parents: 2
diff changeset
   134
            if(title.contains("\"", Qt::CaseInsensitive))
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   135
                title.replace(QString("\""), QString("&#34"));
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
            QString url = query.value(1).toString();
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   137
            if(url.contains("'", Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   138
                url.replace(QString("'"), QString("&#39"));
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   139
            if(url.contains("\"", Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   140
                url.replace(QString("\""), QString("&#34"));
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
            QString date = query.value(2).toString();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
            QString tag = query.value(3).toString();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
            int aIndex=query.value(4).toInt(&ok);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   144
            BookmarkLeaf* node = new BookmarkLeaf();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
            QDate adate = QDate::fromString(date, "dd.MM.yyyy");
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
            node->setTitle(title);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
            node->setUrl(url);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   148
            node->setDate(adate);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   149
            node->setTag(tag);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
            node->setIndex(aIndex);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
            nodeslist.append(node);         
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   152
        }
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   153
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   154
    return nodeslist;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   155
}
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   157
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   158
 * Description: fetches suggested bookmarks from database
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   159
 ================================================================*/
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   160
QList<BookmarkLeaf*> BrowserContent::suggestBookMarks(QString atitle)
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   161
{
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   162
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   163
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   164
    QList<BookmarkLeaf*> nodeslist;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   165
        
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   166
    if (db.isOpen()) {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   167
        QSqlQuery query(db);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   168
        QString queryStatement = "SELECT title,url FROM BookMarkTable WHERE title LIKE '%" + atitle + "%' OR url LIKE '%" + atitle + "%' LIMIT 3";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   169
        query.prepare(queryStatement);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   170
        query.exec();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   171
        QSqlError error = query.lastError();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   172
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   173
        while (query.next()) {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   174
            QString title = query.value(0).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   175
            QString url = query.value(1).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   176
            BookmarkLeaf* node = new BookmarkLeaf();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   177
            node->setTitle(title);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   178
            node->setUrl(url);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   179
            nodeslist.append(node);         
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   180
        }
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   181
    }
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   182
    return nodeslist;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   183
}
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   186
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
 * Description: adds the bookmark to the database
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
 ================================================================*/
3
hgs
parents: 2
diff changeset
   189
int BrowserContent::addHistory(
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
        HistoryLeaf* HistoryContent)
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   191
{
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   193
    QSqlError error;
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
    QString title =HistoryContent->getTitle();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
    QString url = HistoryContent->getUrl();
3
hgs
parents: 2
diff changeset
   196
    QDateTime dt  = QDateTime::currentDateTime();
hgs
parents: 2
diff changeset
   197
    int timestamp = dt.toTime_t();
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   198
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   200
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   201
    if (db.isOpen()) {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   202
        QSqlQuery query(db);
3
hgs
parents: 2
diff changeset
   203
15
hgs
parents: 12
diff changeset
   204
       #ifdef Q_WS_MAEMO_5
hgs
parents: 12
diff changeset
   205
		// Update timestamp on existing entries that have the same URL and title and were time-stamped
hgs
parents: 12
diff changeset
   206
        // within the last 24 hours.  Normally there will only one of these entries.
hgs
parents: 12
diff changeset
   207
        query.prepare(QString("UPDATE HistoryTable "
hgs
parents: 12
diff changeset
   208
                              "SET timestamp=%1 "
hgs
parents: 12
diff changeset
   209
                              "WHERE timestamp>%2 AND url='%3' AND pageTitle='%4'")
hgs
parents: 12
diff changeset
   210
                      .arg(timestamp)
hgs
parents: 12
diff changeset
   211
                      .arg(timestamp - (60 * 60 * 24))
hgs
parents: 12
diff changeset
   212
                      .arg(url)
hgs
parents: 12
diff changeset
   213
                      .arg(title));
hgs
parents: 12
diff changeset
   214
        query.exec();
hgs
parents: 12
diff changeset
   215
        //qDebug() << "==" << __PRETTY_FUNCTION__ << query.executedQuery() << query.numRowsAffected() << query.lastError();
hgs
parents: 12
diff changeset
   216
hgs
parents: 12
diff changeset
   217
        if(query.numRowsAffected() == 0)
hgs
parents: 12
diff changeset
   218
        {
hgs
parents: 12
diff changeset
   219
            // No recent duplicates found, create a new entry.
hgs
parents: 12
diff changeset
   220
            query.clear();
hgs
parents: 12
diff changeset
   221
            query.prepare("INSERT INTO HistoryTable (rowindex,pageTitle, url, domain, timestamp) "
hgs
parents: 12
diff changeset
   222
                           "VALUES (NULL,:title, :url, :domain, :timestamp)");
hgs
parents: 12
diff changeset
   223
hgs
parents: 12
diff changeset
   224
            query.bindValue(":title",  QVariant(title));
hgs
parents: 12
diff changeset
   225
            query.bindValue(":url",    QVariant(url));
hgs
parents: 12
diff changeset
   226
            query.bindValue(":domain", QVariant(filterUrl(url)));
hgs
parents: 12
diff changeset
   227
            query.bindValue(":timestamp",  QVariant(timestamp));
hgs
parents: 12
diff changeset
   228
            query.exec();
hgs
parents: 12
diff changeset
   229
            //qDebug() << "==" << __PRETTY_FUNCTION__ << query.executedQuery() << query.lastError();
hgs
parents: 12
diff changeset
   230
            error = query.lastError();
hgs
parents: 12
diff changeset
   231
        }
hgs
parents: 12
diff changeset
   232
        #else
hgs
parents: 12
diff changeset
   233
        query.prepare("INSERT INTO HistoryTable (rowindex,pageTitle, url, domain, timestamp) "
3
hgs
parents: 2
diff changeset
   234
                       "VALUES (NULL,:title, :url, :domain, :timestamp)");
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   235
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   236
        query.bindValue(":title",  QVariant(title));
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   237
        query.bindValue(":url",    QVariant(url));
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   238
        query.bindValue(":domain", QVariant(filterUrl(url)));
15
hgs
parents: 12
diff changeset
   239
				query.bindValue(":timestamp",  QVariant(timestamp));
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   240
        query.exec();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   241
        error = query.lastError();
15
hgs
parents: 12
diff changeset
   242
        #endif
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   243
    }
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   244
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   245
    if (error.type() == QSqlError::NoError) {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   246
          return ErrNone;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   247
    } else {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   248
       return ErrGeneral;
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   249
    }
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   250
}
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   252
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   253
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   254
 * Description: fetches History From database
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   255
 ================================================================*/
3
hgs
parents: 2
diff changeset
   256
QList<HistoryLeaf*> BrowserContent::fetchHistory()
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   257
{
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   258
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   259
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   260
    QList<HistoryLeaf*> nodeslist;
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   261
    
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   262
    bool dbopen = db.isOpen();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   263
    bool ok;
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   264
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   265
    if (dbopen) {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   266
        QSqlQuery query(db);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   267
3
hgs
parents: 2
diff changeset
   268
		query.prepare("SELECT pagetitle,url,rowindex,timestamp FROM HistoryTable ORDER BY timestamp ASC");
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   269
        query.exec();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   270
        QSqlError error = query.lastError();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   271
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   272
        while (query.next()) {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   273
            QString title = query.value(0).toString();
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   274
            if(title.contains("\"", Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   275
                title.replace(QString("\""), QString("&#34"));
9
hgs
parents: 6
diff changeset
   276
            //--Encoding backslash used in title--
hgs
parents: 6
diff changeset
   277
            if(title.contains("\\", Qt::CaseInsensitive))
hgs
parents: 6
diff changeset
   278
                title.replace(QString("\\"), QString(KBACKSLASH));
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   279
            QString url = query.value(1).toString();
9
hgs
parents: 6
diff changeset
   280
            //--Encoding doublequote used in title--
hgs
parents: 6
diff changeset
   281
            if(url.contains("\"", Qt::CaseInsensitive))
hgs
parents: 6
diff changeset
   282
                url.replace(QString("\""), QString(KDOUBLEQUOTE));
3
hgs
parents: 2
diff changeset
   283
			int aIndex=query.value(2).toInt(&ok);
hgs
parents: 2
diff changeset
   284
            uint timest = query.value(3).toUInt();
hgs
parents: 2
diff changeset
   285
            QDateTime dtime=QDateTime::fromTime_t ( timest );
hgs
parents: 2
diff changeset
   286
            QDate adate=dtime.date();
hgs
parents: 2
diff changeset
   287
            QTime atime =dtime.time(); 
hgs
parents: 2
diff changeset
   288
            
hgs
parents: 2
diff changeset
   289
			HistoryLeaf* node = new HistoryLeaf();
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   290
            node->setTitle(title);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   291
            node->setUrl(url);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   292
            node->setDate(adate);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   293
            node->setLastVisited(atime);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   294
            node->setIndex(aIndex);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   295
            nodeslist.append(node);         
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   296
        }
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   297
    }
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   298
    return nodeslist;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   299
}
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   301
/**==============================================================
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
 * Description: Clear all rows  From History database
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
 ================================================================*/
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
int BrowserContent::clearHistory()
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
{
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   306
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   307
    QSqlError error;
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   308
    
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   309
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   310
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   311
    if (db.isOpen()) {
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   312
        QSqlQuery query(db);
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   313
        query.prepare("DELETE  FROM  HistoryTable" );
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
        
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   315
    query.exec();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   316
        error = query.lastError();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   317
        
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   318
    if (error.type() == QSqlError::NoError) {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   319
      return ErrNone;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   320
    } else {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   321
      return ErrGeneral;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   322
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   323
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   324
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   325
    return ErrGeneral;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   326
}
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   327
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   328
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   329
 * Description: Clear all rows  From Bookmarks database
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   330
 ================================================================*/
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   331
int BrowserContent::clearBookmarks()
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   332
{
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   333
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   334
    QSqlError error;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   335
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   336
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   337
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   338
    if (db.isOpen()){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   339
        QSqlQuery query(db);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   340
        query.prepare("DELETE  FROM  BookMarkTable" );
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   341
        
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   342
    query.exec();
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   343
        error = query.lastError();
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   344
        
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   345
    if (error.type() == QSqlError::NoError) {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   346
      return ErrNone;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   347
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   348
    else{
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   349
      return ErrGeneral;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   350
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   351
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   352
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   353
    return ErrGeneral;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   354
}
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   355
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   356
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   357
 * Description: fetches suggested History From database
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   358
 ================================================================*/
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   359
QList<HistoryLeaf*> BrowserContent::suggestHistory(QString atitle){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   360
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   361
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   362
    QList<HistoryLeaf*> nodeslist;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   363
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   364
    bool dbopen = db.isOpen();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   365
    if (dbopen){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   366
        QSqlQuery query(db);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   367
        QString queryStatement = "SELECT title,url FROM HistoryTable WHERE title LIKE '%" + atitle + "%' OR url LIKE '%" + atitle + "%'";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   368
        query.prepare(queryStatement);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   369
        query.exec();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   370
        QSqlError error = query.lastError();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   371
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   372
        while (query.next()){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   373
            QString title = query.value(0).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   374
            QString url = query.value(1).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   375
            HistoryLeaf* node = new HistoryLeaf();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   376
            node->setTitle(title);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   377
            node->setUrl(url);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   378
            nodeslist.append(node);         
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   379
        }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   380
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   381
    return nodeslist;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   382
}
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   383
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   384
 * Description: fetches suggested History and Bookmarks From database
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   385
 ================================================================*/
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   386
QObjectList BrowserContent::suggestContent(QString atitle){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   387
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   388
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   389
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   390
  while(!suggestedList.isEmpty()) {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   391
        delete suggestedList.takeFirst();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   392
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   393
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   394
    bool dbopen = db.isOpen();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   395
    if (dbopen){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   396
        QSqlQuery query(db);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   397
        
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   398
    if(atitle.contains("'", Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   399
      atitle.replace(QString("'"), QString("''"));
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   400
 
6
hgs
parents: 3
diff changeset
   401
    QString queryStatement = "SELECT pageTitle,url,1 FROM HistoryTable WHERE pagetitle LIKE '%" + atitle + "%' OR url LIKE '%" + atitle + "%' "+
hgs
parents: 3
diff changeset
   402
    						 " UNION "+
hgs
parents: 3
diff changeset
   403
    						 "SELECT title,url,2 FROM BookMarkTable WHERE title LIKE '%"+atitle+"%' OR url LIKE '%" + atitle + "%'"+
hgs
parents: 3
diff changeset
   404
    						 " ORDER BY 3";
hgs
parents: 3
diff changeset
   405
         
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   406
        query.prepare(queryStatement);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   407
        query.exec();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   408
        QSqlError error = query.lastError();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   409
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   410
        while (query.next()){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   411
            QString bookmarkTitle = query.value(0).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   412
            QString bookmarkUrl =   query.value(1).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   413
            SuggestData* node = new SuggestData(bookmarkTitle, bookmarkUrl);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   414
            suggestedList.append(node);         
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   415
        }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   416
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   417
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   418
  return suggestedList;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   419
}
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   420
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   421
 * Description: removes common strings from URLs
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   422
 ================================================================*/
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   423
QString BrowserContent::filterUrl(QString atitle){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   424
  QString https = "https://";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   425
  QString http = "http://";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   426
  QString www  = "www";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   427
  QString com  = "com";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   428
  QString org  = "org";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   429
  QString htm  = "htm";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   430
  QString html = "html";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   431
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   432
  if(atitle.contains(https, Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   433
    atitle = atitle.remove(https);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   434
  if(atitle.contains(http, Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   435
    atitle = atitle.remove(http);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   436
  if(atitle.contains(www, Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   437
    atitle = atitle.remove(www);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   438
  if(atitle.contains(com, Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   439
    atitle = atitle.remove(com);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   440
  if(atitle.contains(org, Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   441
    atitle = atitle.remove(org);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   442
  if(atitle.contains(html, Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   443
    atitle = atitle.remove(html);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   444
  if(atitle.contains(htm, Qt::CaseInsensitive))
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   445
    atitle = atitle.remove(htm);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   446
  
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   447
    
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   448
  return atitle;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   449
}
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   450
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   451
 * Description: Retrieves the bookmarks and sends it in serialized fashion
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   452
 ================================================================*/
3
hgs
parents: 2
diff changeset
   453
QString BrowserContent::fetchSerializedBookmarks()
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   454
    {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   455
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   456
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   457
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   458
    bool dbopen = db.isOpen();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   459
    bool ok;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   460
    QString bookmakrData = "[";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   461
    if(dbopen)
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   462
        {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   463
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   464
    QSqlQuery query(db);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   465
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   466
    query.prepare("SELECT title,url,adate,tags,rowindex FROM BookMarkTable ORDER BY rowindex");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   467
    query.exec();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   468
    QSqlError error = query.lastError();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   469
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   470
    while (query.next())
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   471
        {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   472
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   473
    QString title = query.value(0).toString();
3
hgs
parents: 2
diff changeset
   474
	if(title.contains("'", Qt::CaseInsensitive))
hgs
parents: 2
diff changeset
   475
        title.replace(QString("'"), QString("&#39"));
hgs
parents: 2
diff changeset
   476
    if(title.contains("\"", Qt::CaseInsensitive))
hgs
parents: 2
diff changeset
   477
        title.replace(QString("\""), QString("&#34"));
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   478
    QString url = query.value(1).toString();
3
hgs
parents: 2
diff changeset
   479
	if(url.contains("'", Qt::CaseInsensitive))
hgs
parents: 2
diff changeset
   480
        url.replace(QString("'"), QString("&#39"));
hgs
parents: 2
diff changeset
   481
    if(url.contains("\"", Qt::CaseInsensitive))
hgs
parents: 2
diff changeset
   482
        url.replace(QString("\""), QString("&#34"));
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   483
    QString date = query.value(2).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   484
    QString tag = query.value(3).toString();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   485
    int aIndex=query.value(4).toInt(&ok);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   486
    bookmakrData.append("{");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   487
    bookmakrData.append("\"title\": \"");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   488
    bookmakrData.append(title);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   489
    bookmakrData.append("\", \"urlvalue\": \"");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   490
    bookmakrData.append(url);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   491
    bookmakrData.append("\"},");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   492
        }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   493
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   494
    bookmakrData.remove(bookmakrData.length(),1);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   495
    bookmakrData.append("]");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   496
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   497
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   498
        }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   499
    return bookmakrData;
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   500
    }
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   501
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   502
3
hgs
parents: 2
diff changeset
   503
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   504
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   505
 * Description: Retrieves the History and sends it in serialized fashion
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   506
 ================================================================*/
3
hgs
parents: 2
diff changeset
   507
void BrowserContent::fetchSerializedHistory(QVector<QString> &folders,QMap<QString,QString> &historyData)
hgs
parents: 2
diff changeset
   508
{
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   509
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   510
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   511
    QList<HistoryLeaf*> nodeslist;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   512
    bool dbopen = db.isOpen();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   513
    bool ok;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   514
    QString history = "";
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   515
3
hgs
parents: 2
diff changeset
   516
    if (!dbopen) {
hgs
parents: 2
diff changeset
   517
		return;
hgs
parents: 2
diff changeset
   518
	}
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   519
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   520
    QSqlQuery query(db);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   521
3
hgs
parents: 2
diff changeset
   522
	query.prepare("SELECT pagetitle,url,rowindex,timestamp FROM HistoryTable ORDER BY timestamp ASC");
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   523
    query.exec();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   524
    QSqlError error = query.lastError();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   525
    int len=query.numRowsAffected();
3
hgs
parents: 2
diff changeset
   526
    
hgs
parents: 2
diff changeset
   527
	while (query.next()) {
hgs
parents: 2
diff changeset
   528
        QString title = query.value(0).toString();
hgs
parents: 2
diff changeset
   529
	    
hgs
parents: 2
diff changeset
   530
		if(title.contains("\"", Qt::CaseInsensitive))
hgs
parents: 2
diff changeset
   531
          title.replace(QString("\""), QString("&#34"));
9
hgs
parents: 6
diff changeset
   532
		if(title.contains("\\", Qt::CaseInsensitive))
hgs
parents: 6
diff changeset
   533
            title.replace(QString("\\"), QString(KBACKSLASH));
3
hgs
parents: 2
diff changeset
   534
        
hgs
parents: 2
diff changeset
   535
		QString url = query.value(1).toString();
9
hgs
parents: 6
diff changeset
   536
		//--Encoding URL--
hgs
parents: 6
diff changeset
   537
        QUrl url1(url);
hgs
parents: 6
diff changeset
   538
        url = QString::fromUtf8(url1.toEncoded());
3
hgs
parents: 2
diff changeset
   539
        uint timest = query.value(3).toUInt();
hgs
parents: 2
diff changeset
   540
        QDateTime dtime=QDateTime::fromTime_t ( timest );
hgs
parents: 2
diff changeset
   541
        QDate adate=dtime.date();
hgs
parents: 2
diff changeset
   542
        QTime atime =dtime.time();
hgs
parents: 2
diff changeset
   543
        int aIndex=query.value(4).toInt(&ok);
hgs
parents: 2
diff changeset
   544
       
hgs
parents: 2
diff changeset
   545
		QDate currentDate = QDateTime::currentDateTime().date();
hgs
parents: 2
diff changeset
   546
        int daysToCurrentDate = adate.daysTo(currentDate);
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   547
3
hgs
parents: 2
diff changeset
   548
        if(daysToCurrentDate < 0) {
hgs
parents: 2
diff changeset
   549
		     continue;
hgs
parents: 2
diff changeset
   550
		}
hgs
parents: 2
diff changeset
   551
		
hgs
parents: 2
diff changeset
   552
        QString foldertitle = findFolderForDate(adate);
hgs
parents: 2
diff changeset
   553
 
hgs
parents: 2
diff changeset
   554
        if(folders.contains(foldertitle)) {
hgs
parents: 2
diff changeset
   555
    		 historyData[foldertitle].append(",");
hgs
parents: 2
diff changeset
   556
        } else  {
hgs
parents: 2
diff changeset
   557
            folders.append(foldertitle);
hgs
parents: 2
diff changeset
   558
               historyData[foldertitle].append("[");
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   559
        }
3
hgs
parents: 2
diff changeset
   560
        historyData[foldertitle].append("{");
hgs
parents: 2
diff changeset
   561
        historyData[foldertitle].append("\"titleVal\": \"");
hgs
parents: 2
diff changeset
   562
        historyData[foldertitle].append(title);
hgs
parents: 2
diff changeset
   563
        historyData[foldertitle].append("\", \"dateVal\": \"");
hgs
parents: 2
diff changeset
   564
        historyData[foldertitle].append(adate.toString("dd.MM.yyyy"));
hgs
parents: 2
diff changeset
   565
        historyData[foldertitle].append("\", \"urlVal\": \"");
hgs
parents: 2
diff changeset
   566
        historyData[foldertitle].append(url);
hgs
parents: 2
diff changeset
   567
        historyData[foldertitle].append("\", \"timeVal\": \"");
hgs
parents: 2
diff changeset
   568
        historyData[foldertitle].append(atime.toString("h:mm ap"));
hgs
parents: 2
diff changeset
   569
	    historyData[foldertitle].append("\"}");
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   570
    }
3
hgs
parents: 2
diff changeset
   571
	for (int i = 0; i < folders.size(); ++i) {
hgs
parents: 2
diff changeset
   572
	  historyData[folders[i]].append("]");
hgs
parents: 2
diff changeset
   573
	}
hgs
parents: 2
diff changeset
   574
}
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   575
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   576
 * Description: Retrieves the bookmark titles and sends it in serialized fashion
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   577
 ================================================================*/
3
hgs
parents: 2
diff changeset
   578
void BrowserContent::fetchAllBookmarkTitles(QVector<QString> &title)
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   579
    {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   580
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   581
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   582
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   583
    bool dbopen = db.isOpen();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   584
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   585
    if(dbopen)
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   586
        {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   587
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   588
    QSqlQuery query(db);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   589
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   590
    query.prepare("SELECT title FROM BookMarkTable");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   591
    query.exec();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   592
    QSqlError error = query.lastError();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   593
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   594
    while (query.next())
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   595
        {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   596
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   597
    title.append(query.value(0).toString());
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   598
        }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   599
        }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   600
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   601
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   602
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   603
 * Description: calculate the folder title
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   604
 ================================================================*/
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   605
QString BrowserContent::findFolderForDate( QDate& nodeDate)
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   606
{
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   607
    QDateTime currentDateTime = QDateTime::currentDateTime();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   608
    int currentDayOfWeek = currentDateTime.date().dayOfWeek(); 
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   609
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   610
    int nodeDayOfWeek = nodeDate.dayOfWeek();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   611
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   612
    int daysToCurrentDate = nodeDate.daysTo(currentDateTime.date());
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   613
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   614
    //Check if date to belongs to "ToDay" Folder
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   615
    if(nodeDate == currentDateTime.date()){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   616
        QString folder = qtTrId("txt_browser_history_today");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   617
        return folder;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   618
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   619
    //Check if date to belongs to "YesterDay" Folder
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   620
    if(nodeDate.addDays(1) == currentDateTime.date() ){
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   621
        QString folder = qtTrId("txt_browser_history_yesterday");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   622
        return folder;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   623
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   624
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   625
    //Check if date to belongs to current week folder
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   626
    //Should disply the day for the current week
3
hgs
parents: 2
diff changeset
   627
    if(daysToCurrentDate > 1 && daysToCurrentDate < 7  &&  currentDayOfWeek > nodeDayOfWeek ){
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   628
        
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   629
        QString folder = qtTrId("txt_browser_history_this_week");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   630
        return folder;
3
hgs
parents: 2
diff changeset
   631
    } 
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   632
3
hgs
parents: 2
diff changeset
   633
    if(daysToCurrentDate > 1 && dateInThisMonth(nodeDate)){
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   634
        QString folder = qtTrId("txt_browser_history_this_month");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   635
        return folder;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   636
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   637
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   638
   QString folder = nodeDate.toString("dd.MM.yyyy");
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   639
   
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   640
    return folder; 
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   641
0
fa475d6462b2 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   642
}
2
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   643
/**==============================================================
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   644
 * Description: calculate whether the date falls with in this month
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   645
 ================================================================*/
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   646
bool BrowserContent::dateInThisMonth(QDate &date)
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   647
{
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   648
    QDate currentDate = QDateTime::currentDateTime().date();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   649
    int daysToCurrentDate = currentDate.daysTo(date);
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   650
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   651
    int currentMonth = currentDate.month();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   652
    int nodeMonth = date.month();
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   653
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   654
    if(daysToCurrentDate <= 31 && currentMonth == nodeMonth) {
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   655
        return true;
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   656
    }
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   657
    return false;  
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   658
   
016bf4557e2f Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   659
}
12
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   660
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   661
QMap<QString, QString> BrowserContent::findSimilarHistoryItems(QString atitle)
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   662
{
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   663
    BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   664
    QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   665
    
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   666
    QMap<QString, QString> map;
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   667
    
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   668
    if (db.isOpen()){
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   669
        QSqlQuery query(db);
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   670
        
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   671
        QString queryStatement = "SELECT url, pageTitle FROM HistoryTable WHERE pageTitle LIKE '%"+atitle+"%' OR url LIKE '%" + atitle + "%'";          
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   672
        query.prepare(queryStatement);
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   673
        if(query.exec()) {    
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   674
            while (query.next()){
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   675
                 QString HistoryUrl = query.value(0).toString();
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   676
                 QString HistoryTitle =   query.value(1).toString();
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   677
                 map.insert( HistoryUrl, HistoryTitle );
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   678
             }
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   679
        } else {
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   680
            QSqlError error = query.lastError();
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   681
        }
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   682
    }
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   683
    return map;
d26902edeef5 201037_03
hgs
parents: 9
diff changeset
   684
}    
15
hgs
parents: 12
diff changeset
   685