Changeset 119

Show
Ignore:
Timestamp:
02/10/08 19:18:38 (1 year ago)
Author:
mike
Message:

[new] smartfolder for Q Control (get rid of default folder)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/English.lproj/MainMenu.nib/classes.nib

    r106 r119  
    8686                                <key>prefLog</key> 
    8787                                <string>id</string> 
    88                                 <key>prefPathChoose</key> 
    89                                 <string>id</string> 
    90                                 <key>prefPathReset</key> 
    91                                 <string>id</string> 
    9288                                <key>prefUpdates</key> 
    9389                                <string>id</string> 
     
    111107                                <key>buttonEdit</key> 
    112108                                <string>NSButton</string> 
     109                                <key>loadProgressIndicator</key> 
     110                                <string>id</string> 
     111                                <key>loadProgressText</key> 
     112                                <string>id</string> 
    113113                                <key>mainWindow</key> 
    114114                                <string>id</string> 
  • trunk/English.lproj/MainMenu.nib/info.nib

    r116 r119  
    1111        <key>IBOpenObjects</key> 
    1212        <array> 
    13                 <integer>221</integer> 
     13                <integer>216</integer> 
    1414        </array> 
    1515        <key>IBSystem Version</key> 
  • trunk/QApplication/QApplicationController.m

    r112 r119  
    4040                        [NSNumber numberWithBool:TRUE], // yellow 
    4141                        [NSNumber numberWithBool:TRUE], // showFullscreenWarning 
    42                         [@"~/Documents/QEMU" stringByExpandingTildeInPath], // standart path 
    4342                        [NSMutableArray array], // known VMs 
    4443                        nil 
     
    4746                        @"yellow", 
    4847                        @"showFullscreenWarning", 
    49                         @"dataPath", 
    5048                        @"knownVMs", 
    5149                        nil]]]; 
     
    6159                if ([userDefaults objectForKey:@"enableCheckForUpdates"]) { 
    6260                        [userDefaults removeObjectForKey:@"enableCheckForUpdates"]; 
     61                } 
     62                if ([userDefaults objectForKey:@"dataPath"]) { 
     63                        [userDefaults removeObjectForKey:@"dataPath"]; 
    6364                } 
    6465#pragma mark TODO:Sparclekey for userdefaults 
  • trunk/QControl/QControlController.h

    r106 r119  
    4747        BOOL isPrefAnimating; 
    4848        BOOL isPrefShown; 
    49         IBOutlet id prefPath; 
    5049        IBOutlet id prefUpdates; 
    5150        IBOutlet id prefLog; 
     
    5554        IBOutlet NSButton *buttonEdit; 
    5655        IBOutlet NSButton *buttonAdd; 
     56         
     57        // loading VMs 
     58        IBOutlet id loadProgressIndicator; 
     59        IBOutlet id loadProgressText; 
     60         
     61        // browsing for qvms 
     62        NSMetadataQuery *query; 
    5763/*       
    5864        // progressPanel 
     
    98104- (IBAction) prefYellow:(id)sender; 
    99105- (IBAction) prefFSWarning:(id)sender; 
    100 - (IBAction) prefPathReset:(id)sender; 
    101 - (IBAction) prefPathChoose:(id)sender; 
    102106 
    103107/* 
  • trunk/QControl/QControlController.m

    r118 r119  
    3232 
    3333 
    34 #define PREFS_HEIGHT 190.0 
     34#define PREFS_HEIGHT 100.0 
    3535 
    3636@implementation QControlController 
     
    4545        qApplication = [NSApp delegate]; 
    4646                 
    47                 // load known VMs 
     47                // load known VMs, search for new VMs 
    4848                [self loadConfigurations]; 
    49  
    50                 // change status to "shutdown" after corrupt termination of QEMU 
    51                 int i; 
    52                 for (i = 0; i < [VMs count]; i++) { 
    53                         if ([[[[VMs objectAtIndex:i] objectForKey:@"PC Data"] objectForKey:@"state"] isEqual:@"running"] ) { 
    54                                 [[[VMs objectAtIndex:i] objectForKey:@"PC Data"] setObject:@"shutdown" forKey:@"state"]; 
    55                                 [[QQvmManager sharedQvmManager] saveVMConfiguration:[VMs objectAtIndex:i]]; 
    56                         } 
    57                 } 
     49                 
     50                // Listen if new VMs are found 
     51                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryFinished:) name:NSMetadataQueryDidFinishGatheringNotification object:query]; 
    5852 
    5953                // Listen to VM updates 
     
    6862 
    6963    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
     64        [query release]; 
    7065        [super dealloc]; 
    7166} 
     
    7671 
    7772#pragma mark TODO: load other nibs 
     73 
     74        NSPredicate *predicate; 
    7875 
    7976        [buttonEdit setCell:[[[QButtonCell alloc] initImageCell:[[buttonEdit cell] image] buttonType:QButtonCellLeft target:[[buttonEdit cell] target] action:[[buttonEdit cell] action]] autorelease]]; 
    8077        [buttonAdd setCell:[[[QButtonCell alloc] initImageCell:[[buttonAdd cell] image] buttonType:QButtonCellRight target:[[buttonAdd cell] target] action:[[buttonAdd cell] action]] autorelease]]; 
    8178         
    82  
     79        // search for qvms 
     80 
     81        query = [[NSMetadataQuery alloc] init]; 
     82        [query setDelegate:self]; 
     83        [loadProgressIndicator startAnimation:self]; 
     84        predicate = [NSPredicate predicateWithFormat:@"kMDItemDisplayName ENDSWITH 'qvm'", nil]; 
     85    [query setPredicate:predicate]; 
     86    [query setSearchScopes:[NSArray arrayWithObject:@"/Users/"]]; 
     87        [query startQuery]; 
     88 
     89         
    8390        // preferences 
    84         [prefPath setStringValue:[[qApplication userDefaults] objectForKey:@"dataPath"]]; 
    8591    if ([[qApplication userDefaults] boolForKey:@"SUCheckAtStartup"]) { 
    8692        [prefUpdates setState:NSOnState]; 
     
    119125{ 
    120126        Q_DEBUG(@"loadConfigurations"); 
    121  
     127         
    122128    if (VMs) 
    123129        [VMs release]; 
    124130 
    125131    VMs = [[NSMutableArray alloc] init]; 
    126     NSString *qvmFile; 
    127132        NSMutableDictionary *tempVM; 
    128     NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:[[qApplication userDefaults] objectForKey:@"dataPath"]]; 
    129     while ((qvmFile = [enumerator nextObject])) { 
    130                 if ([[qvmFile pathExtension] isEqual:@"qvm"]) { 
    131                         tempVM = [[QQvmManager sharedQvmManager] loadVMConfiguration:[NSString stringWithFormat:@"%@/%@", [[qApplication userDefaults] objectForKey:@"dataPath"], qvmFile]]; 
    132                         if (tempVM) 
    133                                 [VMs addObject:tempVM]; 
    134                 } 
    135     } 
     133 
    136134        // add knownVMs 
    137135        int i; 
     
    482480} 
    483481 
    484 - (IBAction) prefPathReset:(id)sender 
    485 
    486         Q_DEBUG(@"prefPathReset"); 
    487  
    488         [[qApplication userDefaults] setObject:[@"~/Documents/QEMU" stringByExpandingTildeInPath] forKey:@"dataPath"]; 
    489         [prefPath setStringValue:[[qApplication userDefaults] objectForKey:@"dataPath"]]
    490 
    491  
    492 - (void) genericFolderSelectPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo 
    493 
    494         Q_DEBUG(@"genericFolderSelectPanelDidEnd")
    495  
    496         [ sheet orderOut:self ]; // hide Sheet 
    497         if ( returnCode == NSOKButton ) { 
    498                [[qApplication userDefaults] setObject:[sheet filename] forKey:@"dataPath"]; 
    499                [prefPath setStringValue:[sheet filename]]; 
    500         } 
    501 
    502  
    503 - (IBAction) prefPathChoose:(id)sender 
    504 
    505         Q_DEBUG(@"prefPathChoose")
    506  
    507         NSOpenPanel *openPanel = [[NSOpenPanel alloc] init]; 
    508         [openPanel setCanChooseDirectories:YES]; 
    509         [openPanel setCanCreateDirectories:YES]; 
    510         [openPanel setCanChooseFiles:NO]; 
    511         [openPanel beginSheetForDirectory:[@"~/Documents" stringByExpandingTildeInPath] 
    512                 file:nil 
    513                types:nil 
    514                 modalForWindow:mainWindow 
    515                modalDelegate:self 
    516                didEndSelector:@selector(genericFolderSelectPanelDidEnd:returnCode:contextInfo:) 
    517                contextInfo:sender]; 
     482 
     483 
     484#pragma mark query handlers 
     485  - (void)queryFinished:(NSNotification*)note 
     486
     487        Q_DEBUG(@"queryFinished")
     488 
     489        int i; 
     490        NSArray *searchResults; 
     491        NSString *VMPath; 
     492        NSMutableArray *knownVMs
     493         
     494        knownVMs = [[[[qApplication userDefaults] objectForKey:@"knownVMs"] mutableCopy] autorelease]; 
     495        searchResults = [(NSMetadataQuery*)[note object] results]; 
     496         
     497        for (i = 0; i < [searchResults count]; i++) { 
     498               VMPath = [[[searchResults objectAtIndex:i] valueForAttribute: (NSString *)kMDItemPath] stringByResolvingSymlinksInPath]; 
     499                if (![knownVMs containsObject:VMPath]) { 
     500                        [knownVMs addObject:VMPath]; 
     501                } 
     502        } 
     503        [[qApplication userDefaults] setObject:knownVMs forKey:@"knownVMs"]
     504 
     505        // change status to "shutdown" after corrupt termination of QEMU 
     506        for (i = 0; i < [VMs count]; i++) { 
     507               if ([[[[VMs objectAtIndex:i] objectForKey:@"PC Data"] objectForKey:@"state"] isEqual:@"running"] ) { 
     508                       [[[VMs objectAtIndex:i] objectForKey:@"PC Data"] setObject:@"shutdown" forKey:@"state"]; 
     509                       [[QQvmManager sharedQvmManager] saveVMConfiguration:[VMs objectAtIndex:i]]; 
     510                } 
     511        } 
     512 
     513        [loadProgressText setHidden:TRUE]; 
     514        [loadProgressIndicator stopAnimation:self]; 
     515        [table reloadData]; 
    518516} 
    519517 
  • trunk/QControl/QControlTableView.m

    r113 r119  
    2929 
    3030 
    31 #define ICON_WIDTH 12.0 
    32 #define ICON_HEIGHT 12.0 
     31#define ICON_WIDTH 9.0 
     32#define ICON_HEIGHT 9.0 
     33#define ICON_X 45.0 
     34#define ICON_Y 31.0 
    3335 
    3436@implementation QControlTableView 
     
    189191         
    190192        // edit icon 
    191         point = NSMakePoint(cellRect.origin.x + cellRect.size.width - 4 * (ICON_WIDTH + 4), cellRect.origin.y + cellRect.size.height - (ICON_HEIGHT + 4)); 
     193        point = NSMakePoint(cellRect.origin.x + ICON_X + (ICON_WIDTH + 4), cellRect.origin.y + ICON_Y); 
    192194        if (NSPointInRect(pointClicked, NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT))) { 
    193195            qFraction = 1.0; 
     
    206208                } 
    207209        [qEditIcon 
    208             drawAtPoint: point 
    209             fromRect: NSMakeRect(0, 0, ICON_WIDTH, ICON_HEIGHT
     210            drawInRect: NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT) 
     211            fromRect: NSMakeRect(0, 0, [qEditIcon size].width, [qEditIcon size].height
    210212            operation: NSCompositeSourceOver 
    211213            fraction: qFraction 
     
    213215 
    214216        // play/pause icon 
    215         point = NSMakePoint(cellRect.origin.x + cellRect.size.width - 3 * (ICON_WIDTH + 4), cellRect.origin.y + cellRect.size.height - (ICON_HEIGHT + 4)); 
     217        point = NSMakePoint(cellRect.origin.x + ICON_X + 2 * (ICON_WIDTH + 4), cellRect.origin.y + ICON_Y); 
    216218        if (NSPointInRect(pointClicked, NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT))) { 
    217219            qFraction = 1.0; 
     
    243245                } 
    244246        [image 
    245             drawAtPoint: point 
    246             fromRect: NSMakeRect(0, 0, ICON_WIDTH, ICON_HEIGHT
     247            drawInRect: NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT) 
     248            fromRect: NSMakeRect(0, 0, [image size].width, [image size].height
    247249            operation: NSCompositeSourceOver 
    248250            fraction: qFraction 
     
    250252 
    251253        // stop icon 
    252         point = NSMakePoint(cellRect.origin.x + cellRect.size.width - 2 * (ICON_WIDTH + 4), cellRect.origin.y + cellRect.size.height - (ICON_HEIGHT + 4)); 
     254        point = NSMakePoint(cellRect.origin.x + ICON_X + 3 * (ICON_WIDTH + 4), cellRect.origin.y + ICON_Y); 
    253255        if (NSPointInRect(pointClicked, NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT))) { 
    254256            qFraction = 1.0; 
     
    267269                } 
    268270        [qStopIcon 
    269             drawAtPoint: point 
    270             fromRect: NSMakeRect(0, 0, ICON_WIDTH, ICON_HEIGHT
     271            drawInRect: NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT) 
     272            fromRect: NSMakeRect(0, 0, [qStopIcon size].width, [qStopIcon size].height
    271273            operation: NSCompositeSourceOver 
    272274            fraction: qFraction 
     
    274276         
    275277        // delete icon 
    276         point = NSMakePoint(cellRect.origin.x + cellRect.size.width - (ICON_WIDTH + 4), cellRect.origin.y + cellRect.size.height - (ICON_HEIGHT + 4)); 
     278        point = NSMakePoint(cellRect.origin.x + ICON_X + 4 * (ICON_WIDTH + 4), cellRect.origin.y + ICON_Y); 
    277279        if (NSPointInRect(pointClicked, NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT))) 
    278280            qFraction = 1.0; 
     
    282284            qFraction = 0.5; 
    283285        [qDeleteIcon 
    284             drawAtPoint: point 
    285             fromRect: NSMakeRect(0, 0, ICON_WIDTH, ICON_HEIGHT
     286            drawInRect: NSMakeRect(point.x, point.y, ICON_WIDTH, ICON_HEIGHT) 
     287            fromRect: NSMakeRect(0, 0, [qDeleteIcon size].width, [qDeleteIcon size].height
    286288            operation: NSCompositeSourceOver 
    287289            fraction: qFraction 
  • trunk/QControl/QControlTableViewController.m

    r116 r119  
    8282 
    8383    id VM; 
    84     NSString *platform; 
    8584        NSString *state; 
     85        NSString *name; 
     86        NSString *path; 
     87        NSColor *color; 
    8688        QDocument *qDocument; 
    87  
    88         platform = @""; 
    89         VM = [[qControl VMs] objectAtIndex:rowIndex]; 
    90         qDocument = [[NSDocumentController sharedDocumentController] documentForURL:[[VM objectForKey:@"Temporary"] objectForKey:@"URL"]]; 
    91         if (qDocument) { 
    92                 switch ([qDocument VMState]) { 
    93                         case(QDocumentSaving): 
    94                                 state = NSLocalizedStringFromTable(@"saving", @"Localizable", @"vmstate"); 
    95                                 break; 
    96                         case(QDocumentSaved): 
    97                                 state = NSLocalizedStringFromTable(@"saved", @"Localizable", @"vmstate"); 
    98                                 break; 
    99                         case(QDocumentLoading): 
    100                                 state = NSLocalizedStringFromTable(@"loading", @"Localizable", @"vmstate"); 
    101                                 break; 
    102                         case(QDocumentPaused): 
    103                                 state = NSLocalizedStringFromTable(@"paused", @"Localizable", @"vmstate"); 
    104                                 break; 
    105                         case(QDocumentRunning): 
    106                                 state = NSLocalizedStringFromTable(@"running", @"Localizable", @"vmstate"); 
    107                                 break; 
    108                         case(QDocumentEditing): 
    109                                 state = NSLocalizedStringFromTable(@"editing", @"Localizable", @"vmstate"); 
    110                                 break; 
    111                         case(QDocumentInvalid): 
    112                                 state = NSLocalizedStringFromTable(@"invalid", @"Localizable", @"vmstate"); 
    113                                 break; 
    114                         default: 
    115                                 state = NSLocalizedStringFromTable(@"shutdown", @"Localizable", @"vmstate"); 
    116                                 break; 
    117                 } 
    118         } else { 
    119                 state = NSLocalizedStringFromTable([[VM objectForKey:@"PC Data"] objectForKey:@"state"], @"Localizable", @"vmstate"); 
    120         } 
     89        NSMutableParagraphStyle *paragraphStyle; 
     90        NSMutableAttributedString *attrString; 
     91 
    12192     
    12293    if ([[aTableColumn identifier] isEqualTo: @"image"]) { 
     
    12899    } 
    129100    else if ([[aTableColumn identifier] isEqualTo: @"description"]) { 
    130          
    131         if ([[[VM objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"x86"]) { 
    132             platform = [NSString stringWithString:@"x86 PC"]; 
    133         } else if ([[[VM objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"x86-64"]) { 
    134             platform = [NSString stringWithString:@"x86-64 PC"]; 
    135         } else if ([[[VM objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"PowerPC"] && [[[VM objectForKey:@"Temporary"] objectForKey:@"-M"] isEqual:@"prep"]) { 
    136             platform = [NSString stringWithString:@"PPC PREP"]; 
    137         } else if ([[[VM objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"PowerPC"]) { 
    138             platform = [NSString stringWithString:@"PPC PowerMac"]; 
    139         } else if ([[[VM objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"SPARC"]) { 
    140             platform = [NSString stringWithString:@"SPARC"]; 
    141         } else if ([[[VM objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"MIPS"]) { 
    142             platform = [NSString stringWithString:@"MIPS"]; 
    143         } else if ([[[VM objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"ARM"]) { 
    144             platform = [NSString stringWithString:@"ARM"]; 
    145         } 
    146          
    147         NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat: @"%@\n", [[[[VM objectForKey:@"Temporary"] objectForKey:@"URL"] path] lastPathComponent]] attributes:[NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]] autorelease]; 
     101 
     102                VM = [[qControl VMs] objectAtIndex:rowIndex]; 
     103                qDocument = [[NSDocumentController sharedDocumentController] documentForURL:[[VM objectForKey:@"Temporary"] objectForKey:@"URL"]]; 
     104                if (qDocument) { 
     105                        switch ([qDocument VMState]) { 
     106                                case(QDocumentSaving): 
     107                                        state = NSLocalizedStringFromTable(@"saving", @"Localizable", @"vmstate"); 
     108                                        break; 
     109                                case(QDocumentSaved): 
     110                                        state = NSLocalizedStringFromTable(@"saved", @"Localizable", @"vmstate"); 
     111                                        break; 
     112                                case(QDocumentLoading): 
     113                                        state = NSLocalizedStringFromTable(@"loading", @"Localizable", @"vmstate"); 
     114                                        break; 
     115                                case(QDocumentPaused): 
     116                                        state = NSLocalizedStringFromTable(@"paused", @"Localizable", @"vmstate"); 
     117                                        break; 
     118                                case(QDocumentRunning): 
     119                                        state = NSLocalizedStringFromTable(@"running", @"Localizable", @"vmstate"); 
     120                                        break; 
     121                                case(QDocumentEditing): 
     122                                        state = NSLocalizedStringFromTable(@"editing", @"Localizable", @"vmstate"); 
     123                                        break; 
     124                                case(QDocumentInvalid): 
     125                                        state = NSLocalizedStringFromTable(@"invalid", @"Localizable", @"vmstate"); 
     126                                        break; 
     127                                default: 
     128                                        state = NSLocalizedStringFromTable(@"shutdown", @"Localizable", @"vmstate"); 
     129                                        break; 
     130                        } 
     131                } else { 
     132                        state = NSLocalizedStringFromTable([[VM objectForKey:@"PC Data"] objectForKey:@"state"], @"Localizable", @"vmstate"); 
     133                } 
     134                path = [[[VM objectForKey:@"Temporary"] objectForKey:@"URL"] path]; 
     135                name = [path lastPathComponent]; 
     136                name = [name substringToIndex:[name length] - 4]; 
     137                paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; 
     138                 
     139                color = [NSColor colorWithDeviceRed:0.5 green:0.5 blue:0.5 alpha:1.0]; 
     140                [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingHead]; 
     141 
     142        attrString = [[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat: @"%@\n", name] attributes:[NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]] autorelease]; 
     143                [attrString appendAttributedString: [[[NSAttributedString alloc] initWithString:[NSString stringWithFormat: @"%@\n", [path stringByDeletingLastPathComponent]]  attributes:[NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize:[NSFont smallSystemFontSize]], NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, color, NSForegroundColorAttributeName, nil]] autorelease]]; 
    148144        [attrString appendAttributedString: [[[NSAttributedString alloc] initWithString:state attributes:[NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]] autorelease]]; 
    149          
     145 
    150146        return attrString; 
    151147    } 
  • trunk/QDocument/QDocumentTaskController.m

    r106 r119  
    181181        cpuTypes = [[[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"i386-softmmu",@"x86_64-softmmu",@"ppc-softmmu",@"sparc-softmmu",@"mips-softmmu",@"arm-softmmu",nil] forKeys:[NSArray arrayWithObjects:@"x86",@"x86-64",@"PowerPC",@"SPARC",@"MIPS",@"ARM",nil]] autorelease]; 
    182182 
    183          
    184183    // if this PC is already running, abort 
    185184    if ([[[[document configuration] objectForKey:@"PC Data"] objectForKey:@"state"] isEqual:@"running"]) {