OSDN Git Service

Merge WebKit at r78450: Initial merge by git.
[android-x86/external-webkit.git] / Tools / MiniBrowser / qt / MiniBrowserApplication.cpp
1 /*
2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2010 University of Szeged
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "MiniBrowserApplication.h"
30
31 #include "utils.h"
32 #include <QRegExp>
33
34 MiniBrowserApplication::MiniBrowserApplication(int& argc, char** argv)
35     : QApplication(argc, argv, QApplication::GuiServer)
36     , m_windowOptions()
37     , m_isRobotized(false)
38     , m_robotTimeoutSeconds(0)
39     , m_robotExtraTimeSeconds(0)
40 {
41     setOrganizationName("Nokia");
42     setApplicationName("QtMiniBrowser");
43     setApplicationVersion("0.1");
44
45     handleUserOptions();
46 }
47
48 void MiniBrowserApplication::handleUserOptions()
49 {
50     QStringList args = arguments();
51     QFileInfo program(args.at(0));
52     QString programName("MiniBrowser");
53     if (program.exists())
54         programName = program.baseName();
55
56     if (args.contains("-help")) {
57         qDebug() << "Usage:" << programName.toLatin1().data()
58              << "[-r list]"
59              << "[-robot-timeout seconds]"
60              << "[-robot-extra-time seconds]"
61              << "[-tiled-backing-store]"
62              <<  "[-separate-web-process-per-window]"
63              << "URLs";
64         appQuit(0);
65     }
66
67     int robotIndex = args.indexOf("-r");
68     if (robotIndex != -1) {
69         QString listFile = takeOptionValue(&args, robotIndex);
70         if (listFile.isEmpty())
71             appQuit(1, "-r needs a list file to start in robotized mode");
72         if (!QFile::exists(listFile))
73             appQuit(1, "The list file supplied to -r does not exist.");
74
75         m_isRobotized = true;
76         m_urls = QStringList(listFile);
77     } else {
78         int lastArg = args.lastIndexOf(QRegExp("^-.*"));
79         m_urls = (lastArg != -1) ? args.mid(++lastArg) : args.mid(1);
80     }
81
82     int robotTimeoutIndex = args.indexOf("-robot-timeout");
83     if (robotTimeoutIndex != -1)
84         m_robotTimeoutSeconds = takeOptionValue(&args, robotTimeoutIndex).toInt();
85
86     int robotExtraTimeIndex = args.indexOf("-robot-extra-time");
87     if (robotExtraTimeIndex != -1)
88         m_robotExtraTimeSeconds = takeOptionValue(&args, robotExtraTimeIndex).toInt();
89
90     if (args.contains("-tiled-backing-store"))
91         m_windowOptions.useTiledBackingStore = true;
92
93     if (args.contains("-separate-web-process-per-window"))
94         m_windowOptions.useSeparateWebProcessPerWindow = true;
95 }