Core Animation is one very cool and interesting API provided by Apple in the Leopard version of Mac OS X. Core Animation can be used to attain some really cool effects like the Cover Flow view, which is available and seen in both iTunes and Finder. The Cover Flow has also been included in the new iPods and in the iPhone. It is an animated view of the files that one is browsing, whether the files are images, videos or documents. Cover Flow displays the preview…
This functionality is now available in Leopard and allows developers to take advantage of this feature by means of Core Animation. Core Animation is a part of the Quartz Core framework and is programmable by means of the objective-c API. This is nice if one’s application UI is written completely in Cocoa. However, why should Carbon developers not be able to take advantage of Core Animation? Well, Apple has thought of that as well. They have exposed a new API named the HICocoaView.
HICocoaView
The HICocoaView allows the developer to embed an NSVIew or any control derived from NSView into a Carbon HIView. This means that Core Animation could be included in a Carbon application. For more information on embedding Cocoa NSViews in a Carbon HIView please visit this link:
Since Trolltech’s Qt framework is currently sitting directly on top of Carbon, I thought I would try and get Cover Flow working in a Qt Application by means of creating a custom widget, which I call the QtCoverFlowWidget.
QtCoverFlowWidget
The first thing we need to do is locate the code for Cover Flow. Conveniently, Apple has an example which ships with the freely available developer tools and it’s named CovertFlow. The entire CovertFlow project, including implementation is available in the following location on your disk:
Basically, the bulk of the work is already done for us, thanks to Apple’s example. Now we must figure out how to wrap a QWidget around this implementation, such that we can use this CovertFlow view inside our Qt Application. So Let us begin.
Creating the project
I simply created a main.cpp from which I then generated an Xcode project. My main.cpp looked something like this:
The above will generate a QtCoverFlowExample.xcodeproj which we can open using Xcode 3.0.
Once the project is opened, there are some things that must be done. They are as follows:
Right click on main.cpp and click Info. In the General tab switch the File Type to “sourcecode.cpp.objcpp”. This is done to let the compiler know that this file contains objective c++ code.
Add QuartzCore and Cocoa frameworks to the project. AppKit framwork can be removed since the Cocoa framework acts as an umbrella around AppKit.
Import the relevant files from the CovertFlow project into our project. They are:
and View.nib must go to the Resources folder (create one if one does not exist)
The project should resemble something similar to this once the aforementioned steps have been completed…
Now that the project is created, we must create our custom widget that will display the CovertFlow view which is written using the Quartz Core framework.
Below is the code to our custom widget named QtCoverFlowWidget
classQtCoverFlowWidget:publicQWidget{Q_OBJECTpublic:QtCoverFlowWidget(QWidget*parent=0):QWidget(parent){// instantiate controller for the covertflow viewHIViewRefcoverFlowRef;controller=[[Controlleralloc]init];//HICocoaView wrapper around covert flow viewHICocoaViewCreate([controllerview], 0, &coverFlowRef);create(WId(coverFlowRef));// connect resize of parent to resize of ourselvesconnect(parent, SIGNAL(resized(int, int)), this, SLOT(slotResize(int, int)));}virtual ~QtCoverFlowWidget(){}protectedslots:voidslotResize(intw, inth){// resize ourselvesresize(w, h-20);}private:Controller*controller;};
We derive the QtCoverFlowWidget from the QWidget class. The CovertFlow example that Apple provides is a classic example of an MVC application. Therefore, in the constructor of our custom widget, we instantiate the controller associated with the CovertFlow example. We then create and HICocoaView which wraps the NSView containing the Cover Flow view and then associate our widget with the HIViewRef associated with the HIView wrapping the NSView which contains the Cover Flow view. This is made possible by the fact that a QWidget is just an HIView on its own. Carbon API can be used to communicate directly to the QWidget, which is an HIView. There are some useful Qt functions which help bridge Carbon and the Qt API. These functions are:
// returns an HIViewRef/WindowPtr which is associated with the QWidgetHIViewRefqt_mac_hiview_for(constQWidget*w)WindowPtrqt_mac_window_for(constQWidget*w)
// returns HIViewRef for a native Carbon Window and vise versaHIViewRefqt_mac_hiview_for(WindowPtrw)WindowPtrqt_mac_window_for(HIViewRefhiview)
In order for the above functions to be used in code, all you need to do is #include <QtGui>.
We also have a slot implemented named slotResize(int, int). This slot is hooked to the resized(int, int) signal which is emitted by the parent of this widget (our QMainWindow implementation). This can be seen in the example code here:
The parent widget is actually a custom widget as well. Specifically, it is a custom implementation of the QMainWindow. Not much happens in this implementation except the interception of the resizeEvent(QResizeEvent *) and the action of emitting the resized(int, int) signal once that occurs.
Last steps
There are also a few things that must be done in order to have a properly integrated Cocoa event loop. The main function needs the following:
The above code ensures the Cocoa event loop is running and properly handling Cocoa events.
Now we can simply instantiate our custom QtCoverFlowWidget just like we do any other Qt Widget. All the code, including the Xcode project as well as the binaries can be found here…
The HICocoaView made the above possible. The HICocoaView is a power class allowing developers to mix Cocoa views inside their Carbon application. Perhaps next time we’ll do something with Apple’s QTKit.
I have been using Xcode 3.0 for some time now. It has worked quite well in production for me. Full of features and enhancements make it one of the best development environments to work with. One of the features which particularly strikes me as genius is the Project Organizer. This feature is available from the Window menu.
Not only does the organizer allow the developer to maintain a number of Xcode projects in an effectively organized way, but it also allows for building Makefile projects. This is in fact something new from Apple and is extremely convenient. Open source projects fit favorably in the little window which is brilliant to say the least.
But let’s take it one step further, not only is the Organizer an organizer, but it is also a lightweight SCM system. Sure it is a local, file based SCM system, but it is extremely useful.
This lightweight SCM functionality is by no means a replacement for the SCM system one uses. It is extremely light weight and allows for better organizing changes made on the local machine. This is quite beneficial for my needs as I often work on code involving a large number of changes which I perform incrementally. Once I reach a stable or satisfactory state of the development task, I simply create a snapshot. The reason I do so is because quite often it is not desired to check in one’s partial changes to the main code repository used by your project team, as it may inflict unnecessary, yet inadvertent, pain on them. This feature allows the developer to experiment effectively while maintaining a coherent and easily accessible history of changes. I often code in a location where there is no internet access and I am unable to check in my desired changes for example. During those times, I can simply create a snapshot and restore later when I am ready to perform the check in to the public code tree.
Let’s move on… so I began coding and I created a snapshot before hand. I made some changes and decided to Create another snapshot. Let’s see what this looks like…
As you can see, the file differences in the “Files Changed” list are displayed and right below that is the differences results, provided by Xcode’s built-in diff tool. Yes, it does look very similar to filemerge. The toolbar provides few operations but gives the user the ability to create more snapshots, delete snapshots and of course restore your project state to a particular snapshot.
Finally, the Organizer also possesses an editor, thus allowing the developer to perform all of his/her work from inside the Organizer.
Software configuration management (SCM) is an essential part of the development lifecycle process. An SCM tool assists in the development process and increases individual and overall team productivity. Because most developers use some type of Integrated Development Environment (IDE), it greatly benefits the development team to have an SCM tool that integrates with the IDE of their choice. Developers generally prefer to stay within the boundaries of their IDE when developing and maintaining code. Switching between an SCM tool and the IDE slows down the development process and prevents developers from reaching a high level of efficiency. Convenience and ease of use are also important issues when working with an SCM tool, therefore the SCM tool must seamlessly integrate with the IDE. A number of SCM tools for the Windows platform support the Microsoft Source Code Control Interface (MSSCCI), which allows providers to integrate into Microsoft’s Visual Studio suite. This article provides a glimpse into the MSSCCI. Seapine’s Surround SCM is used to illustrate a sophisticated integration with Visual Studio .NET 2005.
As a Linux user I am often asked or confronted about my distribution of choice. More often than not I respond with a statement that mimics the following: well, it depends on what I need out of the distro. Quickly, I’m met with; did you see this new distro that just came out? Did you see its package management tool? Did you see this… did you see that… etc.
For me, more often than not, the package management tool is the deciding factor in choosing a new Linux distribution. But what if someone has an old box; a development box, a web server box, a firewall, a box to run some services or compile some code or whatever. This machine runs a Linux distro which is so old, that you find yourself deciding on whether to wipe the hard drive and install a new distro or perform a manual update/upgrade. Many older Linux distributions don’t have an easy way to execute an update/upgrade. So what does one do?
Well, I am one of those people. I have an old machine running Slackware 8 and I recently ran into such a situation. Yes, I know the distribution is old and I should probably move to a newer version, but as long as updated packages/patches exist for it, I’m in a comfort zone, thanks to SWaret.
SWaret has saved me a ton of time, primarily because I did not wipe my box and go back to configuring the new installed OS to the way it was. SWaret takes care of all the little things I do not want to do manually to keep my machine updated and secure. For some slack users, this could take an extended amount of time, especially when packages have multiple dependencies.
So, SWaret, well, it takes care of dependencies, updates, upgrades, removal of packages and more, plus it’s easy to use and beats Slackware’s out of the box pkgtool. No it doesn’t have a web interface yet (although I think it’s in the works). However, it does have a GUI front end to it. The GUI front end does not come with the package, but it’s a separate project called QtSwaret aimed at Slackware and Slackware based distros. SWaret is not restricted for use on older Slackware distributions; it also works very well on new Slackware distros.
Trolltech, a company based in Oslo Norway with additional locations in the United States, China and Germany, never stops innovating. To some it is known as the backbone of the GUI in Linux. To others, it is just a convenient way to provide a cross-platform solution. A powerful and easy to use Window Manager, often called a Desktop Environment, KDE, which ships with most current Linux distributions, is written using Trolltech’s Qt framework. KDE also has plenty of other Qt based applications that are a part of the package. The GUI elements and windows are friendly to the eye and provide high levels of customization.
For those who are not familiar with Qt (or cute as the Trolltech engineers refer to it), it is a rich framework that allows for cross-platform development using an extensive C++ based API. Underneath Qt is written in native, platform specific code to allow for such prosperous functionality. Callbacks are a term of the past with Qt’s original signal/slot mechanism.
Up until now, Qt was the popular beast in Trolltech’s long line of products, which also includes QTopia. However, last month Trolltech released Qt Jambi Development Preview. Qt Jambi is a Qt based framework, which allows a developer to use Qt’s power in Java applications. Developers will now be able to use the Qt API in their Java applications and will seamlessly integrate C++ and Java languages in other projects.
There are of course a number of issues that Trolltech had to deal with when working on this product. How do you handle Qt value types vs object types? How do you handle references, or pointers to references? What about memory management? Since Java doesn’t have multiple inheritance, how does Qt Jambi handle that? And what about protected members of a class? Qt Jambi takes care of all these issues and Trolltech has done a fantastic job in employing proper mappings. All the details are described in the Qt Jambi white paper.
This product, as it evolves, should provide a great level of convenience for a developer such as myself. If you’ve never heard of Qt, or never wanted to use C++ with Java via JNI because of its abstract nature, I’d strongly recommend checking out this developer preview.
Attending WWDC 2006 in San Francisco California was electrifying. It took place at the Moscone center, located in downtown San Fran. The crowd was young, energetic and eager to be enlightened.
The first day started off with the keynote speech led by Steve Jobs, followed by a series of sessions, or a curriculum as I like to refer to it. Mac OS X Leopard was announced along with a number of other features which take the OS to the next level. In addition, a new powerful machine was announced, the Mac Pro!