]> granicus.if.org Git - handbrake/commitdiff
MacGui: When launching a second instance of HB, warn of existing instance and do...
authordynaflash <dynaflashtech@gmail.com>
Mon, 16 Mar 2009 14:55:44 +0000 (14:55 +0000)
committerdynaflash <dynaflashtech@gmail.com>
Mon, 16 Mar 2009 14:55:44 +0000 (14:55 +0000)
- Note: this does not mean multi-instance encoding off of one queue file works. For now its just better than messing up the first instances queue. Also useful for ui developing on one instance sans encoding while actually encoding with another instance.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2261 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/Controller.h
macosx/Controller.mm

index b3c425e5332b9173ecce7ffa3293865b1f771544..619fb88172ee310433707497bebf34d22a5221e6 100644 (file)
@@ -394,5 +394,7 @@ BOOL                        fIsDragging;
 - (void) remindUserOfSleepOrShutdown;
 
 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex;
+
+- (int) hbInstances;
 @end
 
index 36cd1b79cf6bb62b8e4b402845cb13a480cd4132..f56e622f7d8867e34df503e5483cf6645fe0250b 100644 (file)
@@ -142,26 +142,48 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         
         /*On Screen Notification*/
         NSString * alertTitle;
-        if (fWorkingCount > 0)
+        
+        /* We check to see if there is already another instance of hb running.
+         * Note: hbInstances == 1 means we are the only instance of HandBrake.app
+         */
+        if ([self hbInstances] > 1)
         {
-            alertTitle = [NSString stringWithFormat:
-                         NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""),
-                         fWorkingCount,fPendingCount];
+        alertTitle = [NSString stringWithFormat:
+                         NSLocalizedString(@"There is already an instance of HandBrake running.", @"")];
+        NSBeginCriticalAlertSheet(
+                                      alertTitle,
+                                      NSLocalizedString(@"Reload Queue", nil),
+                                      nil,
+                                      nil,
+                                      fWindow, self,
+                                      nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
+                                      NSLocalizedString(@" HandBrake will now load up the existing queue.", nil));    
         }
         else
         {
-            alertTitle = [NSString stringWithFormat:
-                         NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""),
-                         fPendingCount];
+            if (fWorkingCount > 0)
+            {
+                alertTitle = [NSString stringWithFormat:
+                              NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""),
+                              fWorkingCount,fPendingCount];
+            }
+            else
+            {
+                alertTitle = [NSString stringWithFormat:
+                              NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""),
+                              fPendingCount];
+            }
+            
+            NSBeginCriticalAlertSheet(
+                                      alertTitle,
+                                      NSLocalizedString(@"Reload Queue", nil),
+                                      nil,
+                                      NSLocalizedString(@"Empty Queue", nil),
+                                      fWindow, self,
+                                      nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
+                                      NSLocalizedString(@" Do you want to reload them ?", nil));
         }
-        NSBeginCriticalAlertSheet(
-                                  alertTitle,
-                                  NSLocalizedString(@"Reload Queue", nil),
-                                  nil,
-                                  NSLocalizedString(@"Empty Queue", nil),
-                                  fWindow, self,
-                                  nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
-                                  NSLocalizedString(@" Do you want to reload them ?", nil));
+        
         // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
         // right below to either clear the old queue or keep it loaded up.
     }
@@ -180,6 +202,24 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     }
 }
 
+- (int) hbInstances
+{
+    /* check to see if another instance of HandBrake.app is running */
+    NSArray *runningAppDictionaries = [[NSWorkspace sharedWorkspace] launchedApplications];
+    NSDictionary *aDictionary;
+    int hbInstances = 0;
+    for (aDictionary in runningAppDictionaries)
+       {
+        //     NSLog(@"Open App: %@", [aDictionary valueForKey:@"NSApplicationName"]);
+        
+        if ([[aDictionary valueForKey:@"NSApplicationName"] isEqualToString:@"HandBrake"])
+               {
+            hbInstances++;
+               }
+       }
+    return hbInstances;
+}
+
 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
 {
     if (returnCode == NSAlertOtherReturn)
@@ -198,8 +238,11 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     }
     else
     {
-    [self setQueueEncodingItemsAsPending];
-    [self showQueueWindow:NULL];
+        if ([self hbInstances] == 1)
+        {
+            [self setQueueEncodingItemsAsPending];
+        }
+        [self showQueueWindow:NULL];
     }
 }