Saturday, June 18, 2011

Vodafone USB Modem on Ubuntu 10.10

[Note: I also tried the following commands/steps on Ubuntu 11.04 from a virtual machine, but could not test the hardware. You can give it a try]


As mentioned here, the last driver for Vodafone USB modem on Ubuntu is for Ubuntu 10.04, and it is a beta version. I still gave these steps a try on Ubuntu 10.10 and hoped it worked (and it did).

I had to go through two ways to run the USB modem.

Way #1:

1- Install the dependencies as mentioned on website, except for python-gnome2-extras (which is not available). And also two important drivers.

sudo apt-get install wvdial hal python-twisted python-serial python-sqlite python-tz python-gobject python-dbus python-cairo python-crypto python-gtk2 python-gnome2  lsb-release python-glade2
sudo apt-get install usb-modeswitch ozerocdoff

2- Download the Vodafone USB Connect folder from this link.

3- Uncompress the package and install it.
[assuming I downloaded it in /tmp]
cd /tmp
tar xvfz Ubuntu.tgz
cd ./Ubuntu
sudo dpkg -i vodafone-mobile-connect_2.20.01-1_all.deb

4- Run the application from the terminal with the command
vodafone-mobile-connect-card-driver-for-linux
or from the Applications/Internet menu.









Way #2:

After trying this and working with it, I had today the following problem: the USB modem was not recognized, and did not want to get recognized for a while (but after a couple of hours I tried again and worked fine).


So I tried to search for another solution and found that option from the connections icon to "Set up a Mobile Broadband Connection"




[as far as I know, the plans are: Contract,Prepaid]


But this way does not give me the options I use like: Usage, Speed, SMS.



This was all my experience with Vodafone USB Modem on Ubuntu 10.10. I hope it helps.

Thursday, June 2, 2011

Qt Folder Compression

I needed a compression module that does not depend on anything but Qt, and I mean a module to compress a complete folder with its children. This is because I wanted the compression module to work on any platform supported by Qt with no other dependencies. So I made this modules that only uses only qCompress() & qUncompress() methods plus some logic.

It is mainly a recursive algorithm that serializes data into a single file, each with its relative path to the parent folder. And deserializing is just taking binary data, creating needed subfolders, and saving the file.

Download: QtFolderCompressor.zip

[FolderCompressor.h]
#ifndef FOLDERCOMPRESSOR_H
#define FOLDERCOMPRESSOR_H

#include <QFile>
#include <QObject>
#include <QDir>

class FolderCompressor : public QObject
{
    Q_OBJECT
public:
    explicit FolderCompressor(QObject *parent = 0);

    //A recursive function that scans all files inside the source folder
    //and serializes all files in a row of file names and compressed
    //binary data in a single file
    bool compressFolder(QString sourceFolder, QString destinationFile);

    //A function that deserializes data from the compressed file and
    //creates any needed subfolders before saving the file
    bool decompressFolder(QString sourceFile, QString destinationFolder);

private:
    QFile file;
    QDataStream dataStream;

    bool compress(QString sourceFolder, QString prefex);
};

#endif // FOLDERCOMPRESSOR_H


[FolderCompressor.cpp]
#include "FolderCompressor.h"

FolderCompressor::FolderCompressor(QObject *parent) :
    QObject(parent)
{
}

bool FolderCompressor::compressFolder(QString sourceFolder, QString destinationFile)
{
    QDir src(sourceFolder);
    if(!src.exists())//folder not found
    {
        return false;
    }

    file.setFileName(destinationFile);
    if(!file.open(QIODevice::WriteOnly))//could not open file
    {
        return false;
    }

    dataStream.setDevice(&file);

    bool success = compress(sourceFolder, "");
    file.close();

    return success;
}

bool FolderCompressor::compress(QString sourceFolder, QString prefex)
{
    QDir dir(sourceFolder);
    if(!dir.exists())
        return false;

    //1 - list all folders inside the current folder
    dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
    QFileInfoList foldersList = dir.entryInfoList();

    //2 - For each folder in list: call the same function with folders' paths
    for(int i=0; i<foldersList.length(); i++)
    {
        QString folderName = foldersList.at(i).fileName();
        QString folderPath = dir.absolutePath()+"/"+folderName;
        QString newPrefex = prefex+"/"+folderName;

        compress(folderPath, newPrefex);
    }

    //3 - List all files inside the current folder
    dir.setFilter(QDir::NoDotAndDotDot | QDir::Files);
    QFileInfoList filesList = dir.entryInfoList();

    //4- For each file in list: add file path and compressed binary data
    for(int i=0; i<filesList.length(); i++)
    {
        QFile file(dir.absolutePath()+"/"+filesList.at(i).fileName());
        if(!file.open(QIODevice::ReadOnly))//couldn't open file
        {
            return false;
        }

        dataStream << QString(prefex+"/"+filesList.at(i).fileName());
        dataStream << qCompress(file.readAll());

        file.close();
    }

    return true;
}

bool FolderCompressor::decompressFolder(QString sourceFile, QString destinationFolder)
{
    //validation
    QFile src(sourceFile);
    if(!src.exists())
    {//file not found, to handle later
        return false;
    }
    QDir dir;
    if(!dir.mkpath(destinationFolder))
    {//could not create folder
        return false;
    }

    file.setFileName(sourceFile);
    if(!file.open(QIODevice::ReadOnly))
        return false;

    dataStream.setDevice(&file);

    while(!dataStream.atEnd())
    {
        QString fileName;
        QByteArray data;

        //extract file name and data in order
        dataStream >> fileName >> data;

        //create any needed folder
        QString subfolder;
        for(int i=fileName.length()-1; i>0; i--)
        {
            if((QString(fileName.at(i)) == QString("\\")) || (QString(fileName.at(i)) == QString("/")))
            {
                subfolder = fileName.left(i);
                dir.mkpath(destinationFolder+"/"+subfolder);
                break;
            }
        }

        QFile outFile(destinationFolder+"/"+fileName);
        if(!outFile.open(QIODevice::WriteOnly))
        {
            file.close();
            return false;
        }
        outFile.write(qUncompress(data));
        outFile.close();
    }

    file.close();
    return true;
}

Wednesday, June 1, 2011

ZLib Static Library for Qt/Symbian

I've been surfing the internet looking for the zlib static library -which is missing from the Qt/Symbian SDK. I downloaded and installed some old Symbian SDKs and finally found the needed files.

You can download them from this link


Here is a code example of how I used it:

LIBS+= -lefsrv -lezlib -leikcore -lcone

#include <ezgzip.h>
#include <f32file.h>
#include <ezcompressor.h>
#include <ezdecompressor.h>
#include <ezfilebuffer.h>
#include <eikenv.h>

void CompressFileL(QString sourceFile, QString destinationFile)
{
    TPtrC16 aSrcFile(reinterpret_cast<const TUint16*>(sourceFile.utf16()));
    TPtrC16 aDesFile(reinterpret_cast<const TUint16*>(destinationFile.utf16()));
    
    CEZFileBufferManager* fileCompressor = NULL;
    CEZCompressor* comprsr = NULL;
    RFs iFs = CEikonEnv::Static()->FsSession();
    RFile inFile,outFile;
    User::LeaveIfError(inFile.Open(iFs,aSrcFile,EFileRead));
    CleanupClosePushL(inFile);
    User::LeaveIfError(outFile.Create(iFs,aDesFile,EFileRead | EFileWrite));
    CleanupClosePushL(outFile);

    fileCompressor = CEZFileBufferManager::NewLC(inFile,outFile);
    comprsr = CEZCompressor::NewLC(*fileCompressor,CEZCompressor::EBestCompression);

    TBool res = EFalse;
    do
    {
        res = comprsr->DeflateL();
    }while(res);

    CleanupStack::PopAndDestroy(4);//inputFile,outFile,fileCompressor,comprsr
}


void DecompressFileL(QString sourceFile, QString destinationFile)
{
    TPtrC16 aSrcFile(reinterpret_cast<const TUint16*>(sourceFile.utf16()));
    TPtrC16 aDesFile(reinterpret_cast<const TUint16*>(destinationFile.utf16()));
    
    CEZFileBufferManager* fileCompressor = NULL;
    CEZDecompressor* decomprsr = NULL;
    RFs iFs = CEikonEnv::Static()->FsSession();
    RFile inFile,outFile;
    User::LeaveIfError(inFile.Open(iFs,aSrcFile,EFileRead));
    CleanupClosePushL(inFile);
    User::LeaveIfError(outFile.Create(iFs,aDesFile,EFileRead | EFileWrite));
    CleanupClosePushL(outFile);

    fileCompressor = CEZFileBufferManager::NewLC(inFile,outFile);
    decomprsr = CEZDecompressor::NewLC(*fileCompressor);

    TBool res = EFalse;
    do
    {
        res = decomprsr->InflateL();
    }while(res);

    CleanupStack::PopAndDestroy(4);//inputFile,outFile,fileCompressor,decomprsr
}