Thursday 30 June 2011

Understanding KeyUserManger.cpp

What are the functions do we need?
  1. UpdateUserData
    • Arguments:
      • alkuserinfo object
      • any other alkuser object whose data we need to update
      • QString &User
    • It will take the data related with the alkuser object and update it with the existing database
    • If the data didnt exists(will check using checkUserInfoExist()) it will call the InsertUserInfo function and insert the respective values
  2. InsertUserInfo
    • Arguments
      • alkuserinfo object
      • any other alkuser object whose data we need to insert
      • QString &User
    • will do the same thigs as the above
  3. checkUserInfoExist()

QDBusArguments

Detailed Description

The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
The class is used to send arguments over D-Bus to remote applications and to receive them back. D-Bus offers an extensible type system, based on a few primitive types and associations of them. See the QtDBus type system page for more information on the type system.
QDBusArgument is the central class in the QtDBus type system, providing functions to marshall and demarshall the primitive types. The compound types are then created by association of one or more of the primitive types in arrays, dictionaries or structures.
The following example illustrates how a structure containing an integer and a string can be constructed using the QtDBus type system:
struct MyStructure
 {
     int count;
     QString name;
 };
 Q_DECLARE_METATYPE(MyStructure)
In our case MyStructure is AlkUser

 // Marshall the MyStructure data into a D-Bus argument
 QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
 {
     argument.beginStructure();
     argument << mystruct.count << mystruct.name;
     argument.endStructure();
     return argument;
 }

 // Retrieve the MyStructure data from the D-Bus argument
 const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct)
 {
     argument.beginStructure();
     argument >> mystruct.count >> mystruct.name;
     argument.endStructure();
     return argument;
 }
The type has to be registered with qDBusRegisterMetaType() before it can be used with QDBusArgument.
Therefore, somewhere in your program, you should add the following code:
qDBusRegisterMetaType<MyStructure>();
which we had already done in the backend.cpp 
with the code
qDBusRegisterMetaType<AlkUser>();
 
Once registered, a type can be used in outgoing method calls (placed with QDBusAbstractInterface::call()), signal emissions from registered objects or in incoming calls from remote applications.
It is important to note that the operator<< and operator>> streaming functions must always produce the same number of entries in case of structures, both in reading and in writing (marshalling and demarshalling), otherwise calls and signals may start to silently fail.
The following example illustrates this wrong usage in context of a class that may contain invalid data:
// Wrongly marshall the MyTime data into a D-Bus argument QDBusArgument &operator<<(QDBusArgument &argument, const MyTime &mytime) { argument.beginStructure(); if (mytime.isValid) argument << true << mytime.hour << mytime.minute << mytime.second; else argument << false; argument.endStructure(); return argument; } In this example, both the operator<< and the operator>> functions may produce a different number of reads/writes. This can confuse the QtDBus type system and should be avoided.

Reference: http://doc.qt.nokia.com/latest/qdbusargument.html#details
   

What is the use of QVERIFY macro?

The QVERIFY(bool) macro is part of the QtTest module, used to verify whether a given
expression is true. If you want to associate a specific error message when the expression is
false, you can use the QVERIFY2(bool,string) macro, which prints the string when a problem
occurs.
As soon as a test macro fails, the current test case is aborted, so you don’t have to worry
about future macros failing as a result of the first problem. If you need to clean anything up,
do so in the special cleanup slot.
The first test checks that an unspecified date is invalid and a valid date is valid. So Febru-
ary 29 is valid in 1980 (a leap year), but is invalid in 1979.
Listing 16-3. Testing that the isValid method works as expected
void DateTest::testValid()
{
QDate date;
QVERIFY( !date.isValid() );
date = QDate( 1979, 5, 16 );
QVERIFY( date.isValid() );
475
476
CHAPTER 16 ■ UNIT TESTING
date = QDate( 1980, 2, 29 );
QVERIFY( date.isValid() );
date = QDate( 1979, 2, 29 );
QVERIFY( !date.isValid() );
}
It is possible to use QVERIFY to check values as well. For example, QVERIFY(x==4) checks
to see whether x equals 4. The alternative is to write QCOMPARE(x,4) instead. This uses the
QCOMPARE macro to see whether the actual value, x, equals the expected value, 4. The benefit is
that the message returned when a test fails tells you the actual and expected values.
Listing 16-4 shows the QCOMPARE macro in action. The slot shown, testAddMonths, starts by
setting a date. It then adds one month to the given date and ensures that the month part of the
date is updated correctly. It then adds 12 months to the date and sees that the year part of the
data also works.
Listing 16-4. Adding months and checking the results
void DateTest::testAddMonth()
{
QDate date( 1973, 8, 16 );
QCOMPARE( date.year(), 1973 );
QCOMPARE( date.month(), 8 );
QCOMPARE( date.day(), 16 );
QDate next = date.addMonths( 1 );
QCOMPARE( next.year(), 1973 );
QCOMPARE( next.month(), 9 );
QCOMPARE( next.day(), 16 );
next = date.addMonths( 12 );
QCOMPARE( next.year(), 1974 );
QCOMPARE( next.month(), 8 );
QCOMPARE( next.day(), 16 );
}
The testAddDays and testAddYears slots looks very much like the testAddMonths slot. The
year testing slot simply adds a number of years. This is the only test case because the number
of years added affects only the year returned. The test for adding days, however, has three
cases: adding one day (affects only the day property), adding 31 days (affects the month prop-
erty), and adding 366 days (affects the year property).
Putting It Together
The DateTest class is kept in the datetest.cpp and datetest.h files. To create an application,
you must add a main function, which is kept in the main.cpp file shown in Listing 16-5.
The QtTest header that is included first contains all the macros from the QtTest module
(including QVERIFY, QCOMPARE, and so on). The next line includes the class implementing the
actual test. The QTEST_MAIN macro then creates a main function that runs the test cases.
CHAPTER 16 ■ UNIT TESTING
Listing 16-5. The main function is implemented using the QTEST_MAIN macro.
#include <QtTest>
#include "datetest.h"
QTEST_MAIN( DateTest )
This is all referenced from a project file, which has been autogenerated through a call to
qmake –project "CONFIG+=qtestlib console". The qtestlib reference adds a reference to the
QtTest module, while console is required for Windows users. Without it, no messages are
shown. The resulting file is shown in Listing 16-6.
Listing 16-6. The project file puts it all together
######################################################################
# Automatically generated by qmake (2.01a) ti 23. jan 18:26:56 2007
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += datetest.h
SOURCES += datetest.cpp main.cpp
CONFIG += qtestlib console
When all files are in place, it’s then just a matter of building and executing the test.
Running the Tests
The result of building a unit test is an ordinary application. If you run that application without
any command-line arguments, it will produce something like Listing 16-7. The output shows
the version of Qt and the version of the qtestlib used, which is followed by the result of each
test case. In this case, all get a PASS, and the summary at the end shows that all tests have
passed.
■ If you want colored output, set the environment variable QTEST_COLORED to 1.
Tip
Listing 16-7. Running the test without any arguments
********* Start testing of DateTest *********
Config: Using QTest library 4.2.2, Qt 4.2.2
PASS
: DateTest::initTestCase()
PASS
: DateTest::testAddDay()
477
478
CHAPTER 16 ■ UNIT TESTING
PASS
: DateTest::testAddMonth()
PASS
: DateTest::testAddYear()
PASS
: DateTest::testValid()
PASS
: DateTest::cleanupTestCase()
Totals: 6 passed, 0 failed, 0 skipped
********* Finished testing of DateTest *********
Sometimes a test case hangs. When this occurs, it is handy to use the –v1 command-line
argument when executing the test application. When this flag is given, the output tells you
when each test is entered and passed, so you can tell where the test hangs. A snippet of an
output is shown in Listing 16-8.
Listing 16-8. Running the test with the –v1 flag
********* Start testing of DateTest *********
Config: Using QTest library 4.2.2, Qt 4.2.2
INFO
: DateTest::initTestCase() entering
PASS
: DateTest::initTestCase()
INFO
: DateTest::testAddDay() entering
PASS
: DateTest::testAddDay()
INFO
: DateTest::testAddMonth() entering
PASS
: DateTest::testAddMonth()
INFO
: DateTest::testAddYear() entering
...
If you still have a problem locating a hang or just want to make sure that all tests are
run, you can use the –v2 argument, which makes the test output when each test is entered
and passed (just as when using -v1), but it also shows when each testing macro is reached.
Listing 16-9 shows how this looks. Each macro has a line that tells you where it is located—it
reads something like this: filename.ext (line) : failure location.
Listing 16-9. Running the test with the –v2 flag
********* Start testing of DateTest *********
Config: Using QTest library 4.2.2, Qt 4.2.2
INFO
: DateTest::initTestCase() entering
PASS
: DateTest::initTestCase()
INFO
: DateTest::testAddDay() entering
INFO
: DateTest::testAddDay() COMPARE()
datetest.cpp(10) : failure location
INFO
: DateTest::testAddDay() COMPARE()
datetest.cpp(11) : failure location
INFO
: DateTest::testAddDay() COMPARE()
datetest.cpp(12) : failure location
INFO
: DateTest::testAddDay() COMPARE()
...
CHAPTER 16 ■ UNIT TESTING
When a test fails, the current test case is stopped immediately. The macro causing the fail-
ure will report what went wrong and where it is located, just as for the –v2 flag. An example of
a failure can be seen in Listing 16-10. The output is from a test being executed without any
command-line arguments.
If a test case fails, the others still run, so you can obtain a complete accounting of the test
status.
Listing 16-10. A test fails.
********* Start testing of DateTest *********
Config: Using QTest library 4.2.2, Qt 4.2.2
PASS
: DateTest::initTestCase()
PASS
: DateTest::testAddDay()
FAIL! : DateTest::testAddMonth() Compared values are not the same
Actual (next.day()): 16
Expected (15): 15
datetest.cpp(43) : failure location
PASS
: DateTest::testAddYear()
PASS
: DateTest::testValid()
PASS
: DateTest::cleanupTestCase()
Totals: 5 passed, 1 failed, 0 skipped
********* Finished testing of DateTest *********
The reason for the failure was that the expected value in the QCOMPARE macro was changed
on line 43 in datetest.cpp.
If you want to limit the tests to just one test case, you can pass the name of the slot as a
command-line argument. For example, running datetest testValid runs only the testValid
test case.



Wednesday 29 June 2011

What is the use of Q_OBJECT macro?

I just started using Qt and noticed that all the example class definitions have the macro Q_OBJECT as the first line. What is the purpose of this preprocessor macro?

Ans: It simply tells the pre-compiler that this class has gui elements and needs to be run through the 'moc' you only need to add this to classes that use the signal/slot mechanism.
But it will be quietly ignored in any other classes - it just adds to the build time.

Any further answers are welcome

Change the name of the ouput file while compiling using bash in ubuntu

Well If you are compiling using terminal in Ubuntu or Kubuntu
Then you must be writing the command as follows:
g++ abc.cpp
Where abc.cpp is the name of my file which i need to compile
and i end up the file named a.out
But when there are other .cpp files in the folder and then compile them, then this one gets overwritten
So, we need to name it which can be done simply by just replacing the above command you wrote with the following command:
g++ -o abc abc.cpp
here you will have an output file named as "abc"
you can write anything you want in place of "abc"
I just like to write the same name to avoid confusion

Using IRC

Register your IRC Nick


Basically, the way it works is, you register your nickname with a password and an email address. Now everytime you come back to the network, you will be asked to identify yourself using a simple command. This will make sure that you hold on to your nickname and nobody steals it on you.

The command to register usually is...

/msg nickserv register PASSWORD EMAIL

You must replace PASSWORD with a password of your choice and EMAIL with a VALID email address. It must be valid as some networks like you to verify it exists by sending you an email. Once you have registered your nick, when you come back to the network you must identify yourself, you can do this with these commands..

/msg nickserv identify PASSWORD

OR

/nickserv identify PASSWORD (should work, does on most networks)

Replace password with the password that you used to register your nick. Now all you have to do is NOT forget your password.

Check out Various options


You can type the command
/commands
It will show you various type of commands
and to view how these command works you can always type
/help command-name


Now If you want to write some status, or act, then you can use the command
/me


For e.g
/me going for dinner


It will not give the output as
<user> going for dinner
but as follows:
user going for dinner
and yes, it will be in italics


If you got disconnected, and your nickname is already in use.

If your nickname is registered, you can use the ghost command.
/nickserv ghost nickname password
This kills the old session, and allows you to rename yourself with the /nick command. You will still need to identify/login.

I registered my nick and now someone else has it. Did someone steal it? How do I get it back? To keep your registered nick, you must continue to use it. If you do not identify to your nick, it may eventually become expired. Once it becomes expired, someone can ask to have it dropped. When a nick has been dropped and picked up by another user, we are not able to take it back from them. That would be unfair to the user who picked it up. In other cases, someone could simply be using the nick while unidentified. You can force them to change their nick with:
/MSG NickServ RELEASE yournick yourpassword
You may need to run the above command a second time if you get a message saying the nick is temporarily unavailable. You can also set enforce on your nick to have NickServ force users to identify to the account within 30 seconds in order to continue to use it:
/MSG NickServ SET ENFORCE ON
/AWAY [away message] Sets your status as away with some info.
Sets a message explaining that you are not currently paying attention to IRC. Whenever someone sends you a MSG or does a WHOIS on you, they automatically see whatever message you have set. Using AWAY with no parameters marks you as no longer being away.
If you are using XCHAT, then you can use /back to come back to the original state

Monday 27 June 2011

Studying mainwindow.cpp of alkimia/ui

QDBusConnection::sessionBus();
Returns a QDBusConnection object opened with the session bus. The object reference returned by this function is valid until the application terminates, at which point the connection will be closed and the object deleted.

Sunday 26 June 2011

Questions arising while designing Payment Detection Usecase of Alkimia

  1. How will the data be accessed for the 'USER' and other entities?

  2. What is the use of "pluginsDir.cdUp();"?
    • bool QDir::cdUp()
      Changes directory by moving one directory up from the QDir's current directory.
      Returns true if the new directory exists and is readable; otherwise returns false. Note that the logical cdUp() operation is not performed if the new directory does not exist.
      reference: http://doc.trolltech.com/4.2/qdir.html#cdUp

  3. The whole statement is as shown below
    pluginsDir.cdUp();
      if (!pluginsDir.cd("plugins")) {
        qWarning() << "SymbolManager: Couldn't find plugin directory";
        return;
      }
    I do have the directory named "plugins" but still it is giving me the error as shown in the code
    "SymbolManager: Couldn't find plugin directory"
    I don't know why
  4. What exactly does the 'symbol' refers to? How it is related to the user?

    A stock symbol or ticker symbol is a short abbreviation used to uniquely identify publicly traded shares of a particular stock on a particular stock market. A stock symbol may consist of letters, numbers or a combination of both. "Ticker symbol" refers to the symbols that were printed on the ticker tape of a ticker tape machine.
    Reference: http://en.wikipedia.org/wiki/Tilcker_symbol
     
  5. What is the use of Q_OBJECT macro?

    Please refer to the page http://summer-opensource.blogspot.com/2011/06/what-is-use-of-qobject-macro.html

    Running Alkimia Quotes

    After building Alkimia Quotes, It asks you to select an executable, where you got two options:
    1. Run Frontend, to run the UI
      • Location: qtcreator-build/ui/quotefrontend
    2. Run Backend, which runs the dbus service
      • Location: qtcreator-build/backend/quotebackend

    The backend should be started automatically when a matching dbus
    request is received, but starting it manually will give you better
    output.
     

    Error got while building kraft

    I got this error while building KRAFT using QT-creator



    -- Found Qt-Version 4.7.0 (using /usr/bin/qmake)

    -- Found X11: /usr/lib/libX11.so

    -- Found KDE 4.5 include dir: /usr/include

    -- Found KDE 4.5 library dir: /usr/lib

    -- Found the KDE4 kconfig_compiler preprocessor: /usr/bin/kconfig_compiler

    -- Found automoc4: /usr/bin/automoc4

    CMake Error at /usr/share/kde4/apps/cmake/modules/FindPackageHandleStandardArgs.cmake:198 (MESSAGE):

    Could NOT find KdepimLibs (missing: KdepimLibs_CONFIG)

    Call Stack (most recent call first):

    /usr/share/kde4/apps/cmake/modules/FindKdepimLibs.cmake:80 (find_package_handle_standard_args)

    CMakeLists.txt:7 (find_package)

    -- Configuring incomplete, errors occurred!



    So i added the kdepimlibs5-dev using the ubuntu software center, after which i got the following output

    .

    .

    .


    -- Found automoc4: /usr/bin/automoc4

    -- Found KdepimLibs: /usr/lib/cmake/KdepimLibs/KdepimLibsConfig.cmake

    CMake Error at /usr/share/kde4/apps/cmake/modules/FindPackageHandleStandardArgs.cmake:198 (MESSAGE):

    Could NOT find Ctemplate (missing: CTEMPLATE_INCLUDE_DIR

    CTEMPLATE_LIBRARIES)

    Call Stack (most recent call first):

    cmake/modules/FindCtemplate.cmake:23 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)

    CMakeLists.txt:8 (find_package)

    -- Configuring incomplete, errors occurred!



    After this i installed the libctemplate-dev again using the ubuntu software center after which i am able to build it successfully with the following output


    -- Found automoc4: /usr/bin/automoc4

    -- Found Ctemplate: /usr/include

    -- Configuring done

    -- Generating done

    -- Build files have been written to: /home/puneet/puneet/office/qtcreator-build



    Now after running cmake, when i tried to build it, I got the following error

    /usr/include/akonadi/itempayloadinternals_p.h:28: error: boost/shared_ptr.hpp: No such file or directory


    which i thought that i have not installed the boost libraries yet

    So installed the boost library libboost1.4.2-dev again using the ubuntu software center

    After which this issue was resolved when i again clicked on the icon to build it

    However i still got some warnings as shown as follows


    /home/puneet/puneet/office/kraft/src/models/modeltest.cpp:468: warning: unused parameter ‘end’

    /home/puneet/puneet/office/kraft/src/models/modeltest.cpp:520: warning: unused parameter ‘parent’

    /home/puneet/puneet/office/kraft/src/models/modeltest.cpp:520: warning: unused parameter ‘start’

    /home/puneet/puneet/office/kraft/src/models/modeltest.cpp:520: warning: unused parameter ‘end’

    /home/puneet/puneet/office/kraft/src/external/ktreeviewsearchline.cpp:192: warning: unused parameter ‘treeView’


    But i ignored the warnings and clicked on the Run icon


    and it showed with a new window of kraft application :D

    with the following output in the application ouput window of QT-creator

    http://pastebin.com/FJzFYE5p

    Error got while building Alkimia Quotes

    In building using QT-creator i didnt get any error but when i hit the run icon,
    It opened the new window of front end but its menu bar was not working and even the compile output f Qt-creator following error came

    SymbolManager: Couldn't find plugin directory