#import <UIKit/UIKit.h>
#import <sqlite3.h>
#import "Tunebook.h"
#import "Tune.h"
#import "Reachability.h"

@class Playlist;
@class MainViewController;
@class ManageTunesController;
@class SettingsController;
@class PlaylistViewController;
@class TuneViewController;
@class TuneDatabase;

@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarDelegate>
{
	IBOutlet UIWindow *window;
	IBOutlet UINavigationController *navigationController;
	IBOutlet UIViewController *topViewController;
	IBOutlet UIView *loadingView;
	IBOutlet MainViewController *tunesViewController;
	IBOutlet UIViewController *playlistViewController;
	IBOutlet UIViewController *favouritesViewController;
	IBOutlet UIViewController *searchViewController;
	IBOutlet UIViewController *settingsController;
  IBOutlet ManageTunesController *manageTunesController;
	IBOutlet UITabBar *tabBar;
	IBOutlet UITabBarController *tabBarController;
	IBOutlet UIView *tabView;
	IBOutlet UIView *rootView;
#if TARGET_IPAD
  TuneViewController *tuneViewController;
#endif
	UIViewController *currentViewController;
  NSMutableArray *tunes;
  NSMutableArray *playlists;
  NSMutableArray *filesToImport;
  NSMutableDictionary *settings;
  Reachability *reachability;
  TuneDatabase* database;

  float playerVolume;
	float playerSpeed;
  int playerVoice;
  BOOL guitarChords;
  BOOL loopPlayback;
  BOOL preventSleep;
  BOOL initializedDatabase;
  int selectedTab;
  int currentTune;
  int transitionType;
  float tuneScaling;
}

@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) UIViewController *topViewController;
#if TARGET_IPAD
@property (nonatomic, retain) TuneViewController *tuneViewController;
#endif

@property (nonatomic, retain) TuneDatabase* database;
@property (nonatomic, retain, readonly) NSMutableArray *tunes;
@property (nonatomic, retain, readonly) NSMutableArray *playlists;
@property (nonatomic, retain) NSMutableDictionary *settings;
@property (nonatomic, retain) Reachability *reachability;

@property (nonatomic, assign) float playerVolume;
@property (nonatomic, assign) float playerSpeed;
@property (nonatomic, assign) int playerVoice;
@property (nonatomic, assign) int tuneSortOrder;
@property (nonatomic, assign) BOOL guitarChords;
@property (nonatomic, assign) BOOL loopPlayback;
@property (nonatomic, assign) BOOL preventSleep;
@property (nonatomic, readonly) BOOL initializedDatabase;
@property (nonatomic, assign) int currentTune;
@property (nonatomic, assign) int transitionType;
@property (nonatomic, assign) float tuneScaling;

- (void)initializeDatabase;
- (void)startTransaction;
- (void)commitTransaction;

- (IBAction)removeTune:(Tune *)tune;
- (void)addTune:(Tune *)tune;
- (void)deleteAllTunes;
- (void)sortTunes;
- (void)savePreferences;

- (IBAction) onImportTunes:(id)sender;

- (void)addPlaylist:(Playlist *)playlist;
- (void)removePlaylist:(Playlist *)playlist;

- (void)searchForTunes:(NSString *)searchText tunes:(NSArray *)tunelist results:(NSMutableArray *)results;
- (void)searchForTunesWithTitle:(NSString *)titleText key:(NSString *)keyText meter:(NSString *)meterText tunes:(NSArray *)tunelist results:(NSMutableArray *)results;
- (void)searchForDots:(NSString *)searchText tunes:(NSArray *)tunelist results:(NSMutableArray *)results;

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;

- (void)threadRun:(id)sender;
- (void)importFiles:(id)sender;

- (void)showTuneController:(TuneViewController *)controller;

- (id)tuneWithPrimaryKey:(NSInteger)pk;

@end

@interface RootViewController : UIViewController
{
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

@end
