File indexing completed on 2024-12-01 07:24:48

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KDB_SIMPLECMDLINEAPP_H
0021 #define KDB_SIMPLECMDLINEAPP_H
0022 
0023 #include <KDbConnection>
0024 
0025 #include <KAboutData>
0026 
0027 class KCmdLineOptions;
0028 class KComponentData;
0029 
0030 //! @short A skeleton for creating a simple command line database application.
0031 /*! This class creates a KComponentData object and automatically handles the following
0032  command line options:
0033  - --driver \<id\> (Database driver ID) or -drv
0034  - --user \<name\> (Database user name) or -u
0035  - --password (Prompt for password) or -p
0036  - --host \<name\> (Server (host) name) or -h
0037  - --port \<number\> (Server's port number)
0038  - --local-socket \<filename\> (Server's local socket filename, if needed) or -s
0039 
0040  You can use this helper class to create test applications or small tools that open
0041  a KDb-compatible database using command line arguments, do some data processing
0042  and close the database.
0043 */
0044 class KDB_EXPORT KDbSimpleCommandLineApp : public KDbObject
0045 {
0046     Q_DECLARE_TR_FUNCTIONS(KDbSimpleCommandLineApp)
0047 public:
0048     KDbSimpleCommandLineApp(
0049         int argc, char** argv,
0050         const KCmdLineOptions &options, const char *programName,
0051         const char *version, const char *shortDescription = 0,
0052         KAboutData::LicenseKey licenseType = KAboutData::License_Unknown,
0053         const char *copyrightStatement = 0, const char *text = 0,
0054         const char *homePageAddress = 0, const char *bugsEmailAddress = "submit@bugs.kde.org");
0055 
0056     ~KDbSimpleCommandLineApp();
0057 
0058     //! @return program instance
0059     const KComponentData &componentData() const;
0060 
0061     /*! Opens database @a databaseName for connection data
0062      specified via the command line. @return true in success.
0063      In details: the database driver is loaded, the connection is opened
0064      and the database is used.
0065      Use KDbObject methods to get status of the operation on failure. */
0066     bool openDatabase(const QString& databaseName);
0067 
0068     /*! Closes database connection previously opened using openDatabase()
0069      @return true on success. This method is called on destruction.
0070      Use KDbObject methods to get status of the operation on failure. */
0071     bool closeDatabase();
0072 
0073     /*! @return connection data for this application. */
0074     KDbConnectionData* connectionData() const;
0075 
0076     /*! @return connection object for this application or 0 if there is no properly
0077      opened connection. */
0078     KDbConnection* connection() const;
0079 
0080 protected:
0081     class Private;
0082     Private * const d;
0083     Q_DISABLE_COPY(KDbSimpleCommandLineApp)
0084 };
0085 
0086 #endif