Showing posts with label applications. Show all posts
Showing posts with label applications. Show all posts

Saturday, May 23, 2009

Re-installing Windows

I have a book behind me called "Backup & Recovery" from O'Reilly Publishing. I have learn a very basic yet very important lesson from that book... And If my memory is right it goes something like:
"Your backups are as good as your last restoration attempt."

The whole concept being that even though you have backups, unless your actually tried to restore those backups, they don't mean anything.

Since:
  • Microsoft came out with an RC of Windows 7
  • I ran Windows XP which could only see 3.5G out of 8G of physical RAM
  • I'm been making backups of everything on my computer
I decided it was time to test that backup strategy with a fresh install of Windows. Of course, because Windows 7 RC will shutdown in 2010, I will have to re-do this process all over again.

Thus, I am writing here everything that I have to do in case I need to do it again. (This posting will be updated if anything changes during the year)

This Machine is use for: Gaming, Web, E-mail and the occasional programming in C++ / QT.

List of software I need to get online (in alphabetical order):
  • 7zip
  • Adobe Air
  • Allsnap
  • ClipX
  • Boinc
  • Dropbox
  • Firefox
  • Flash player
  • Foxit Reader
  • gnucash
  • Launchy (no 64bit version, but 32bit seems to work)
  • Nokia Qt SDK
  • OpenOffice.org
  • Pidgin
  • Picasa
  • Process Explorer
  • Putty
  • QDevelop
  • SMplayer
  • Steam
  • Thunderbird
  • VirtualBox
  • Vlc
  • WinDirStat
  • WinSCP
  • Xming
List of Backup procedures:
  • Backed-up "Documents and Settings" Folder from Windows XP
  • Backed-up "My Documents" Folder from Windows XP
  • Backup list of mods in Oblivion Mod Manager and Fallout 3 mod Manager
  • Imaged the C: Partition with CloneZilla (just in case)

List of Restore procedures:
  • Moved the "My Documents", "My Pictures", etc as sub-folders of "D:\My Documents"
  • Show File Extentions. Always. (Control Panel -> Folder options)
  • Add "path=C:\Qt\2009.02\mingw\bin;C:\Qt\2009.02\qt\bin" variable in Control Panel -> System -> Advance -> Environment Variables
  • Re-installed Firefox extentions (including: Xmarks, Noscript, Delicious bookmarks, IE tab ,etc)
  • Restore Thunderbird directories:
  1. Documents and Settings\Ve2dmn\Application Data\Thunderbird to C:\Users\Ve2dmn\AppData\Roaming\Thunderbird
  2. Documents and Settings\Ve2dmn\Local Settings\Application Data\Thunderbird to C:\Users\Ve2dmn\AppData\Local\Thunderbird
The rest is mostly tweaking.

I guess I have proven to myself I'm somewhat protected against data loss now... Eventually I will have something like Time Machine, TimeVault or Flyback for Windows, but for now, I guess this will have to do :)

Monday, April 06, 2009

Small live stream recorder with Qt

I decided to try to write a small App with Qt (no, quicktime, but the Nokia toolkit, Qt)

The result is the screenshot you see. It's an app called, the "Twit Live Recorder V0.1 (Proof of Concept)". It's a live stream preview and recorder, with the ability to "split" the current file (it create a new file and add -1 or -2, -3 and so on...). It is very rough code, but it works. (you could probably crash it if you try hard enough)

Note: I took Twit Live as an example because I know that Leo gaves his O.K. to have his stream recorded (ODTV is great! You guys rules!). This could probably apply to any live stream that can be recorded with 'wget' or 'curl'. I won't give the urls here because I have no idea if it violates the terms of service for Stickam, Ustream or Bitgravity (or even Justin.tv). As always, uses your jugement and don't do anything illegal.

Also note that simply copying and pasting the code will probably not work. I removed some characters that were interpreted as htnl code and replace them with "quotes". If someone wants the original files, I could post them somewhere.

Final Note: This was done for fun, as an exercise. I'm probably not going to maintaint this application, as I don't see the use for it. (The OdTV people are already working on automation...) I'm not a full-time C++ developper and probably lack the experience to answer. If you have C++ or Qt Question you are probably better off asking it on a forum dedicated to that like StackOverflow.

The Code Behind the App
I used QDevelop to create the App, but it could probably be built with QtCreator, Kdevelop, MS Visual Studio or the command line.

The entire app is basically 5 files: a .pro project ( Twit Live Recorder.pro), a main.cpp , the .ui file (twit_live_recorder.ui), and the .cpp and .h of the main object (twitliverecorderimpl.cpp and .h )

The .pro "project" file:
TEMPLATE = app
QT += core webkit network
FORMS += ui/twit_live_recorder.ui
SOURCES += src/twitliverecorderimpl.cpp src/main.cpp
HEADERS += src/twitliverecorderimpl.h
CONFIG += build_all debug_and_release
TARGET = Twit_Live_Recorder

The file is pretty straightforward. Build a Qt app, with modules "core", "webkit" and "network", with name "Twit_Live_Recorder" (You can also see that I like to build both debug and release.) The qmake from Nokia can turn this file in the coresponding Makefile for the correct architecture and OS.

The main.cpp is also pretty straightforward:


#include "QtGui/QApplication"
#include "twitliverecorderimpl.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TwitLiveRecorderImpl w;
w.show();
return a.exec();
}

Include the "Twit Live Recorder Implementation" called twitliverecorderimpl, create a QApp (to handle most of the OS stuff) , create a TwitLiveRecorderImpl dialog and show it.

I won't copy the content of the .ui because the XML code is not meant to be read. I can tell you it's a QMainWindows with a QWebview as a central widget (to get a preview of the stream). Also includes a QLabel and QLineEdit at the bottom to list the current file. Finally, the main windows includes a MenuBar and Toolbar with the following Qaction: "Record", "Split", "Stop","Quit", "About", and "About Qt"

Now on the the meat of the app, the Dialog Implementation. First the .h:


#ifndef TWITLIVERECORDERIMPL_H
#define TWITLIVERECORDERIMPL_H

#include "QMainWindow"
#include "QFile"
#include "QHttp"
#include "ui_twit_live_recorder.h"

class TwitLiveRecorderImpl : public QMainWindow, public Ui::TwitLiveRecorder
{
Q_OBJECT

public:
TwitLiveRecorderImpl( QWidget * parent = 0, Qt::WFlags f = 0 );

public slots:
void Http_error(bool error);
void Http_stateChanged (int state);

private slots:
void on_action_Quit_activated();
void on_actionAbout_activated();
void on_actionRecord_activated();
void on_actionSplit_Current_Recording_activated();
void on_actionStop_Current_Recording_activated();

private:
QString Host_url;
QString Stream_url;
QString BaseFileName;
QString ActiveFileName;
int SplitNumber;
QFile *ActiveFile;
QHttp *CurrentConnection;

};
#endif

As you can see, this object includes both a QFile and a QHttp private objects. What we do to save the stream is simply open a Http connection to the server and pass the QFile as the destination IO device. The on_action_ slots are function the Qt precompiler will automagically connect with the button on the UI. The Http_error and Http_stateChanged are there mostly to help debugging the Http stream.

Finally, the .ccp file. Let's go trough it one function at a time. First the header and Object Constructor:


#include "twitliverecorderimpl.h"
#include "QMessageBox"
#include "QWebSettings"
#include "QFileDialog"
#include "QFileInfo"
#include "QDate"
#include "QDebug"

TwitLiveRecorderImpl::TwitLiveRecorderImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);

//Set Urls
webView->setUrl(QUrl("http://live.twit.tv"));
Host_url = "Server.whatever.com";
Stream_url = "http://Server.whatever.com/stream-url";

//Create a New Connection (unused until the record button is pressed)
CurrentConnection = new QHttp();
CurrentConnection->setHost(Host_url);

//Set Filename. Default file name looks like: "Twit-2009-03-25.flv"
BaseFileName = "Twit-" +
QDate::currentDate().toString("yyyy-MM-dd");
ActiveFileName ="";

//Split Number to have Twit-2009-03-25-1.flv, etc.
SplitNumber = 0 ;

//Enable Plugins so we can have Flash working
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled,true);

//Connect to "About QT" in the menu
connect(actionAbout_Qt,SIGNAL(activated())
,qApp,SLOT(aboutQt ()));

//Connect Signal from http for debugging
connect(CurrentConnection,SIGNAL(done(bool))
,this,SLOT(Http_error(bool)));
connect(CurrentConnection,SIGNAL(stateChanged(int))
,this,SLOT(Http_stateChanged(int)));
}


Set the inital Values of each Variables as well as connect every signal not automagically connected.

Functions for the "Quit" and "About" Menu Options:

void TwitLiveRecorderImpl::on_action_Quit_activated()
{
close();
}

void TwitLiveRecorderImpl::on_actionAbout_activated()
{
QMessageBox::about( this, tr("Twit Live Recorder"),
tr("Twit Live Recorder v0.1(Proof of Concept)"
"Using QT"));
}



Function to help with Debugging the http connection:

void TwitLiveRecorderImpl::Http_error(bool error)
{
if(error)
{
//Debug Code goes here
}
else
//Debug Code goes here
}
void TwitLiveRecorderImpl::Http_stateChanged ( int state ) { //Debug Code goes here
}


3 Function are left for "Record", "Stop" and "Split". First the "Record" function:


void TwitLiveRecorderImpl::on_actionRecord_activated()
{
ActiveFileName = QFileDialog::getSaveFileName(
this, tr("Please Select File Name"),
"/"+ BaseFileName + ".flv");
if(ActiveFileName == "")
return;

//Change the look of the Buttons:
actionRecord->setDisabled(true);
actionSplit_Current_Recording->setDisabled(false);
actionStop_Current_Recording->setDisabled(false);

ActiveFile = new QFile(ActiveFileName);

//Open Connection to server
CurrentConnection->get(Stream_url,ActiveFile);

//Set Visible "Currently Recording"
Line_CurrentFileName->setText(ActiveFile->fileName());

SplitNumber = 0 ;
}


The important part is the File dialog where the user choose the name and location of the file, that file is then passed-on as a destination for a new connection. The button are also activated or deactivated, depending on which one. The "Stop" function does things in reverse:


void TwitLiveRecorderImpl::on_actionStop_Current_Recording_activated()
{
//Abort Connection to Server
CurrentConnection->abort();

//Reset Displayed File Name
Line_CurrentFileName->setText("");

//Change the look of the Buttons:
actionRecord->setDisabled(false);
actionSplit_Current_Recording->setDisabled(true);
actionStop_Current_Recording->setDisabled(true);
}



Finally the "split" Function:

void TwitLiveRecorderImpl::on_actionSplit_Current_Recording_activated()
{
QFile *PreviousFile = ActiveFile;
SplitNumber++;

//Create new File name based on the Active File
QFileInfo OldFile = QFileInfo(ActiveFileName);
QString NewFileName = OldFile.absolutePath() + OldFile.baseName() + "-" + QString::number( SplitNumber, 16 ) + "." + OldFile.completeSuffix();

//Next File is the new Active File
ActiveFile = new QFile(NewFileName);
ActiveFile->open(QIODevice::WriteOnly);

//Close the Old Connection and open a new one
CurrentConnection->abort();
CurrentConnection->setHost(Host_url);
CurrentConnection->get(Stream_url,ActiveFile);

//Set Visible "Currently Recording"
Line_CurrentFileName->setText(ActiveFile->fileName());
PreviousFile->close();
}


This function opens a new file based on the previous name. Right now it is probably pretty buggy: It does not check if the file already exist nor give any sort of feedback, but the basic functionality is there.

It was a fun app to write and I was surprised at how little I had in the end to get a functioning application. Of course, this doesn't show the all the debugging time I spent on it (a ratio of around 1:5 to 1:6). And I should also give credit where credit is due, becasue this would not have been possible with work from Qt and Webkit. I am standing on the shoulder of giant with this sort of work.

Tuesday, August 19, 2008

My Apps

I lost a couple of hours looking at the Lifehacker Desktop Show and Tell Flickr Pool. It got me thinking about what I use on a daily basis and how my desktop should reflect my current productivity push (I'm basically cleaning up my life, and trying to be more productive. It's not perfect, but I'm slowly getting there)

So, in case my computer exploded, or in case I bought a new machine and had to redo everything from scratch, here is a list of the things I use the most:

On Windows:
  • Launchy: Must have. Good alternatives includes Executor and Dash Command. Quicksilver on Mac.
  • ClipX: I can finaly get a bigger clipboard (Linux had that for ages)
  • allSnap: Snap app to edges of desktop
  • Snarl: Notification system for Windows.  Like Growl on Mac
  • AppSnap: Install free apps. Sort of like a package manager.
  • Mp3tag: I don't have that big of a MP3 collection, but I like my stuff consistent
  • Picasa: Manages pictures from my camera.
  • PuTTY: I use Linux-based servers, sort this is a must-have
  • Xming: To get Linux/Unix X-Windows system on MS Windows. Run graphical application remotly!
  • WinSCP: Copy files. Ftp is too old and too insecure.
  • Flock: The Social-based browser: I'm typing this blog entry in it. Also integrated Facebook, twitter, Youtube, etc...
  • Adobe Air with:

Ironicly, I can get most of this functionality on my Linux desktop (again with the right applications installed), but it's not third party. The only reason I'm not 100% Linux right now is gaming. (TES: Oblivion these days, with a bit of Simcity 4)
Blogged with the Flock Browser