Changeset 1219


Ignore:
Timestamp:
Dec 15, 2006, 1:18:36 AM (15 years ago)
Author:
livings124
Message:

show an error dialog when trying to open another copy of Transmission, and make the formatting match the cocoa-style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r1218 r1219  
    7575+ (void) initialize
    7676{
    77     /* Make sure another Transmission.app isn't running already */
    78     NSString * myBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    79     int myProcessIdentifier = [[NSProcessInfo processInfo] processIdentifier];
    80 
    81     NSDictionary * dico;
     77    //make sure another Transmission.app isn't running already
     78    NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
     79    int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
     80
     81    NSDictionary * dic;
    8282    NSEnumerator * enumerator = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator];
    83     while( ( dico = [enumerator nextObject] ) )
    84     {
    85         if( ![[dico objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: myBundleIdentifier] )
    86         {
    87             /* This isn't Transmission */
    88             continue;
    89         }
    90         if( [[dico objectForKey: @"NSApplicationProcessIdentifier"] intValue] == myProcessIdentifier )
    91         {
    92             /* This is ourselves */
    93             continue;
    94         }
    95        
    96         /* Activate the already running instance, then kill ourselves right away */
    97         NSLog( @"Another instance of Transmission is already running, aborting" );
    98         [[NSWorkspace sharedWorkspace] launchApplication: [dico objectForKey: @"NSApplicationPath"]];
    99         exit( 0 );
     83    while ((dic = [enumerator nextObject]))
     84    {
     85        if ([[dic objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: bundleIdentifier]
     86            && [[dic objectForKey: @"NSApplicationProcessIdentifier"] intValue] != processIdentifier)
     87        {
     88            NSAlert * alert = [[NSAlert alloc] init];
     89            [alert addButtonWithTitle: NSLocalizedString(@"Quit", "Transmission already running alert -> button")];
     90            [alert setMessageText: NSLocalizedString(@"Transmission is already running",
     91                                                    "Transmission already running alert -> title")];
     92            [alert setInformativeText: NSLocalizedString(@"There is already a copy of Transmission running. "
     93                "Please quit that instance before opening another.", "Transmission already running alert -> message")];
     94            [alert setAlertStyle: NSWarningAlertStyle];
     95           
     96            [alert runModal];
     97            [alert release];
     98           
     99            //activate the already running instance, then kill ourselves right away
     100            [[NSWorkspace sharedWorkspace] launchApplication: [dic objectForKey: @"NSApplicationPath"]];
     101            exit(0);
     102        }
    100103    }
    101104
Note: See TracChangeset for help on using the changeset viewer.