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 << "[-maximize]" 59 << "[-r list]" 60 << "[-robot-timeout seconds]" 61 << "[-robot-extra-time seconds]" 62 << "[-chunked-drawing-area]" 63 << "[-separate-web-process-per-window]" 64 << "[-print-loaded-urls]" 65 << "URLs"; 66 appQuit(0); 67 } 68 69 if (args.contains("-maximize")) 70 m_windowOptions.startMaximized = true; 71 72 int robotIndex = args.indexOf("-r"); 73 if (robotIndex != -1) { 74 QString listFile = takeOptionValue(&args, robotIndex); 75 if (listFile.isEmpty()) 76 appQuit(1, "-r needs a list file to start in robotized mode"); 77 if (!QFile::exists(listFile)) 78 appQuit(1, "The list file supplied to -r does not exist."); 79 80 m_isRobotized = true; 81 m_urls = QStringList(listFile); 82 } else { 83 int lastArg = args.lastIndexOf(QRegExp("^-.*")); 84 m_urls = (lastArg != -1) ? args.mid(++lastArg) : args.mid(1); 85 } 86 87 int robotTimeoutIndex = args.indexOf("-robot-timeout"); 88 if (robotTimeoutIndex != -1) 89 m_robotTimeoutSeconds = takeOptionValue(&args, robotTimeoutIndex).toInt(); 90 91 int robotExtraTimeIndex = args.indexOf("-robot-extra-time"); 92 if (robotExtraTimeIndex != -1) 93 m_robotExtraTimeSeconds = takeOptionValue(&args, robotExtraTimeIndex).toInt(); 94 95 if (args.contains("-chunked-drawing-area")) 96 m_windowOptions.useTiledBackingStore = false; 97 98 if (args.contains("-separate-web-process-per-window")) 99 m_windowOptions.useSeparateWebProcessPerWindow = true; 100 101 if (args.contains("-print-loaded-urls")) 102 m_windowOptions.printLoadedUrls = true; 103 } 104