Parent Directory
|
Revision Log
First Import
#import "AppController.h"
@implementation AppController
- (void) applicationDidFinishLaunching : (NSNotification *) aNote {
if( [ [ self OME_Pref : @"" ] isEqualToString : @"" ] || [ [ self OME_Root_Path : @"" ] isEqualToString : @"" ] ){
[ NSApp terminate : NSApp ];
}
nsfm = [ [ NSFileManager defaultManager ] retain ];
//この辺からはCocoaはやっぱり!Web版を参考にしました
NSStatusBar *bar = [ NSStatusBar systemStatusBar ];
sbItem = [ bar statusItemWithLength : 24.0 ];
[ sbItem retain ];
[ sbItem setTitle : @"" ];
[ sbItem setHighlightMode : YES ];
[ sbItem setMenu : OMEnu ];
//この辺まで
if ( [ [ NSUserDefaults standardUserDefaults ] boolForKey : @"AutoReceive" ] ){
[ [ OMEnu itemWithTag : 1 ] setState : NSOnState ];
[ sbItem setImage : [ NSImage imageNamed : @"MenuIcon" ] ];
[ nsfm removeFileAtPath : [ self OME_Pref : @"/NowAutoDL" ] handler : nil ];
if ( [ self HasBehaviorValue : @"CocoaOMEnuUseLaunchAgent" ] ){
[ self loadLaunchAgent ];
}else{
AutoReceiveTimer = [ NSTimer scheduledTimerWithTimeInterval:[ [ self GetBehaviorValue : @"CocoaOMEnuDownloadInterval=" defaultvalue :@"600" ] intValue ] target:self selector:@selector(AutoReceive) userInfo:nil repeats:YES ];
}
}else{
[ [ OMEnu itemWithTag : 1 ] setState : NSOffState ];
[ sbItem setImage : [ NSImage imageNamed : @"MenuIconOff" ] ];
}
//http://www.oomori.com/cocoafw/Foundation/NSTimer/scheduledTimimeInterval2.html参照
UpdateMenuTimer = [ NSTimer scheduledTimerWithTimeInterval:[ [ self GetBehaviorValue : @"CocoaOMEnuMenuUpdateInterval=" defaultvalue:@"30"] intValue ] target:self selector:@selector(UpdateUnread) userInfo:nil repeats:YES];
[ UpdateMenuTimer fire ];
if ( ! [ self HasBehaviorValue : @"CocoaOMEnuUseLaunchAgent" ] ){
if ( [ AutoReceiveTimer isValid ] ){
[ AutoReceiveTimer fire ];
}
}
[ self UpdateReceiveMenu ];
[ self UpdateSenderMenu ];
}
- (IBAction)Cron:(id)sender {
NSUserDefaults *defaults = [ NSUserDefaults standardUserDefaults ];
if ( [ sender state ] == NSOnState ){
[ sender setState : NSOffState ];
[ sbItem setImage : [ NSImage imageNamed : @"MenuIconOff" ] ];
if ( [ self HasBehaviorValue : @"CocoaOMEnuUseLaunchAgent" ] ){
[ self unloadLaunchAgent ];
}else{
if ( [ AutoReceiveTimer isValid ] ){
[ AutoReceiveTimer invalidate ];
}
}
[ defaults setBool : FALSE forKey : @"AutoReceive" ];
}else{
[ sender setState : NSOnState ];
[ sbItem setImage : [ NSImage imageNamed : @"MenuIcon" ] ];
[ defaults setBool : TRUE forKey : @"AutoReceive" ];
if ( [ self HasBehaviorValue : @"CocoaOMEnuUseLaunchAgent" ] ){
[ self loadLaunchAgent ];
}else{
AutoReceiveTimer = [ NSTimer scheduledTimerWithTimeInterval:[ [ self GetBehaviorValue : @"CocoaOMEnuDownloadInterval=" defaultvalue :@"600" ] intValue ] target:self selector:@selector(AutoReceive) userInfo:nil repeats:YES ];
[ AutoReceiveTimer fire ];
}
}
[ defaults synchronize ];
[ self UpdateUnread ];
}
- (IBAction)EnableAllPOPAccounts:(id)sender {
//senderのtag値で「全部受信するように変更」「全部受信しないように変更」切り替え
NSMutableArray *POPArray = [ NSMutableArray arrayWithCapacity : 1 ];
NSMutableString *aSet;
NSString *RcvInfoPath = [ self OME_Pref : @"/Receive_Info.txt" ];
int i,j;
[ POPArray setArray : [ [ NSString stringWithContentsOfFile : RcvInfoPath ] componentsSeparatedByString : @"\x0a" ] ];
for(i = 0 ; i < [ POPArray count ] ; i++){
aSet = [ NSMutableString string ];//入れ替え用データ
j = [ [ [ POPArray objectAtIndex : i ] componentsSeparatedByString : @"," ] count ];
if ( j > 2 ){
//受信設定でないコメントは手を付けない。
[ aSet setString : [ [ POPArray objectAtIndex : i ] stringByTrimmingCharactersInSet : [ NSCharacterSet characterSetWithCharactersInString : @"#" ] ] ];
//とりあえず#を取り除く
if ( [ sender tag ] == 100002 ){
[ aSet insertString : @"#" atIndex : 0 ];
}
//tag値が100002のとき頭に#挿入=受信停止
[ POPArray replaceObjectAtIndex : i withObject : aSet ];
//今作った奴と入れ替える。
}
}
[ [ POPArray componentsJoinedByString : @"\x0a" ] writeToFile : RcvInfoPath atomically : YES ];
//LFで結合して書き込み
[ self UpdateReceiveMenu ];
}
- (IBAction)ReceiverSelected:(id)sender {
int pos = [ sender tag ];
//tag値=NSMutableArrayのindex値。indexと同じとは限らない。
NSMutableArray *POPArray = [ NSMutableArray arrayWithCapacity : 1 ];
NSMutableString *aSet = [ NSMutableString string ];
NSString *RcvInfoPath = [ self OME_Pref : @"/Receive_Info.txt" ];
[ POPArray setArray : [ [ NSString stringWithContentsOfFile : RcvInfoPath ] componentsSeparatedByString : @"\x0a" ] ];
//Receive_Info.txtを読み込み、LFで区切ってNSArrayに変換
if ( [ sender state ] == NSOnState ){
[ aSet setString : [ POPArray objectAtIndex : pos ] ];
//POPArrayのpos番目を取得
[ aSet insertString : @"#" atIndex : 0 ];
//#を頭に入れる=OFFにする
}else{
[ aSet setString:[ [ POPArray objectAtIndex:pos ] stringByTrimmingCharactersInSet : [ NSCharacterSet characterSetWithCharactersInString:@"#" ] ] ];
//#を削除する=ONにする
}
[ POPArray replaceObjectAtIndex : pos withObject : aSet ];
//編集したものと入れ替え
[ [ POPArray componentsJoinedByString : @"\x0a" ] writeToFile : RcvInfoPath atomically : YES ];
//書き込み
[ self UpdateReceiveMenu ];
}
- (IBAction)SenderSelected:(id)sender {
int pos = [ sender tag ];
if ( pos != 0 ){
NSString *SndInfoPath = [ self OME_Pref : @"/Sender_Info.txt" ];
NSArray *tmpAry = [ [ NSString stringWithContentsOfFile : SndInfoPath ] componentsSeparatedByString : @"\x0a" ];
NSMutableArray *SMTPArray = [ NSMutableArray arrayWithCapacity : 1 ];
int i;
for(i = 0 ; i < [ tmpAry count ] - 4 ; i+=4)
[ SMTPArray addObject : [ [ tmpAry subarrayWithRange : NSMakeRange(i, 4) ] componentsJoinedByString : @"\x0a" ] ];
//Sender_Infoは4行で1設定
if ( [ tmpAry count ] == ( i + 4 ) )
[ SMTPArray addObject : [ [ tmpAry subarrayWithRange : NSMakeRange(i, 4) ] componentsJoinedByString : @"\x0a" ] ];
//最後の改行が抜けている時上の行が実行される。
//[ tmpAry count ] == ( i + 4 )の時というのは、設定自体はちゃんとしてあるのだが、最後の改行が足りない状態。
[ SMTPArray addObject : @"" ];
//最後の改行を追加するために@""を追加
for( ; pos > 0 ; pos-- )
[ SMTPArray exchangeObjectAtIndex : pos withObjectAtIndex : pos - 1 ];
//選ばれた設定を1番上に持って行き、その他のを1つずつ下に下げるためにぐるぐる回す
//[ SMTPArray exchangeObjectAtIndex : 0 withObjectAtIndex : pos ];//単に入れ替えるだけだったらこの1行
[ [ SMTPArray componentsJoinedByString : @"\x0a" ] writeToFile : SndInfoPath atomically : YES ];
//LFで結合して書き込み
}
[ self UpdateSenderMenu ];
}
- (IBAction)FindUnreadMails:(id)sender{
NSFileWrapper *MDFindWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : @"/usr/bin/mdfind" ] autorelease ];
NSString *OMEunreadAliases = [ self OME_Root_Path : @"/temp/unreadAliases" ];
NSFileWrapper *OpenWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : OMEunreadAliases ] autorelease ];
if ( ! [ OpenWrapper isDirectory ] ){
[ self SlowFindUnreadMails ];
}else{
NSAppleScript *RevealUnreadMails;
NSDictionary *RevealUnreadMailsError;
NSMutableString *scptPath = [ NSMutableString string ];
[ scptPath setString : [ [ NSBundle mainBundle ] resourcePath ] ];
if ( [ MDFindWrapper isRegularFile ] ){
[ scptPath appendString : @"/Scripts/RevealUnreadMails.scpt" ];
}else{
[ scptPath appendString : @"/Scripts/RevealUnreadMailsViaUnreadAliases.scpt" ];
}
RevealUnreadMails = [ [ [ NSAppleScript alloc ] init ] initWithContentsOfURL : [ NSURL fileURLWithPath : scptPath ] error : &RevealUnreadMailsError ] ;
[ RevealUnreadMails executeAndReturnError : &RevealUnreadMailsError ];
[ RevealUnreadMails release ];
}
}
- (IBAction)UserML:(id)sender{
[ self Mailto : @"ome@groups.mac.com" ];
}
- (void)Mailto:(NSString *)MailAddress{
[ self doOMEScript : [ NSArray arrayWithObjects : @"to",MailAddress,nil ] ];
}
- (IBAction)NewMail:(id)sender{
[ self doOMEScript : [ NSArray arrayWithObjects : @"new",nil ] ];
}
- (IBAction)UpdateMenu:(id)sender{
[ self UpdateReceiveMenu ];
[ self UpdateSenderMenu ];
[ self UpdateUnread ];
}
- (IBAction)SendMails:(id)sender{
NSString *OutBoxPath = [ self OME_Root_Path : @"/OutBox.localized" ];
NSFileWrapper *OpenWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : OutBoxPath ] autorelease ];
NSString *DialogTitle;
NSString *Msg;
if ( ! [ OpenWrapper isDirectory ] ){
OutBoxPath = [ self OME_Root_Path : @"/OutBox" ];
OpenWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : OutBoxPath ] autorelease ];
}
if ( [ OpenWrapper isDirectory ] ){
NSArray *ary = [ [ nsfm directoryContentsAtPath : OutBoxPath ] pathsMatchingExtensions : [ NSArray arrayWithObjects : @"wmail",nil ] ];
NSBundle *bundle = [ NSBundle mainBundle ];
if ( [ ary count ] > 0 ){
if ( [ ary count ] == 1 ){
DialogTitle = [ bundle localizedStringForKey : @"Sending Mail" value : nil table : nil ];
Msg = [ bundle localizedStringForKey : @"DialogMessageSendmail" value : @"Are you sure to send mail ? There is a mail in OutBox folder." table : nil ];
}else{
DialogTitle = [ bundle localizedStringForKey : @"Sending Mails" value : nil table : nil ];
Msg = [ NSString stringWithFormat : [ bundle localizedStringForKey : @"DialogMessageSendmails" value : @"Are you sure to send mail ? There is %u mail in OutBox folder." table : nil ],[ ary count ] ];
}
if ( NSRunAlertPanel(DialogTitle, Msg, [ bundle localizedStringForKey : @"Send" value : nil table : nil ], [ bundle localizedStringForKey : @"Cancel" value : nil table : nil ], NULL ) == NSOKButton ){
[ self doOMEScript : [ NSArray arrayWithObjects : @"send", nil ] ];
}
}else{
NSRunAlertPanel([ bundle localizedStringForKey : @"Sending Mail" value : nil table : nil ],[ bundle localizedStringForKey : @"There is no mail to send." value : nil table : nil ], @"OK", NULL, NULL );
}
}
}
- (IBAction)ReceiveMail:(id)sender{
[ self doOMEScript : [ NSArray arrayWithObjects : @"dl", nil ] ];
}
- (IBAction)OpenPreferencesFolder:(id)sender{
//初期設定フォルダを開く
[ self doOMEScript : [ NSArray arrayWithObjects : @"pref", nil ] ];
}
- (IBAction)OpenMailbox:(id)sender{
//メールボックスフォルダを開く
[ self doOMEScript : [ NSArray arrayWithObjects : @"root", nil ] ];
}
- (IBAction)OpenAddressBook:(id)sender{
//アドレス帳を開く
NSString *OpenPath = [ self OME_Pref : @"/Address_Book" ];
NSFileWrapper *OpenWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : OpenPath ] autorelease ];
if ( [ OpenWrapper isSymbolicLink ] ){
[ [ NSWorkspace sharedWorkspace ] openFile : OpenPath ];
}else{
[ [ NSWorkspace sharedWorkspace] launchApplication:@"Address Book"];
}
}
- (IBAction)iChat:(id)sender{
[ [ NSWorkspace sharedWorkspace] launchApplication:@"iChat"];
[ self OpenLocation : @"aim:gochat?roomname=ome" ];
}
- (IBAction)GururiWeb:(id)sender{
[ self OpenLocation : @"http://gururi.com/" ];
}
- (IBAction)OMEWeb:(id)sender{
[ self OpenLocation : @"http://mac-ome.jp/" ];
}
- (void)OpenLocation:(NSString *)URLString{
[ [ NSWorkspace sharedWorkspace ] openURL : [ NSURL URLWithString : URLString ] ];
}
- (void)UpdateUnread{
//NSLog(@"UpdateUnread");
//NSBundle *bundle = [ NSBundle mainBundle ];
int i = [ self CountUnread ];
if ( i > 0 ){
if ( [ self HasBehaviorValue : @"UnreadFormatVerbose" ] ){
[ sbItem setTitle : [ NSString stringWithFormat : [ [ NSBundle mainBundle ] localizedStringForKey :@"UnreadFormatVerbose" value:nil table:nil ] , i ] ];
}else{
[ sbItem setTitle : [ NSString stringWithFormat : [ [ NSBundle mainBundle ] localizedStringForKey :@"UnreadFormat" value:nil table:nil ] , i ] ];
}
[ sbItem setLength : NSVariableStatusItemLength ];
}else{
[ sbItem setTitle : @"" ];
[ sbItem setLength : 24.0 ];
}
}
- (int)CountUnread{
NSUserDefaults *defaults = [ NSUserDefaults standardUserDefaults ];
[ defaults synchronize ];
NSDictionary *dict = [defaults persistentDomainForName:@"jp.mac-ome.gururi.CocoaOMEnu"];
if ( [ [ dict allKeys ] containsObject : @"Unread" ] ){
return [ defaults integerForKey : @"Unread" ];
}
NSFileWrapper *MDFindWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : @"/usr/bin/mdfind" ] autorelease ];
if ( [ MDFindWrapper isRegularFile ] ){
NSMutableString *comePath = [ NSMutableString string ];
[ comePath setString : [ [ NSBundle mainBundle ] resourcePath ] ];
[ comePath appendString : @"/come" ];
NSTask *task = [ [ [ NSTask alloc ] init ] autorelease ];
NSPipe *pipeStdout = [ NSPipe pipe ];
[ task setLaunchPath : comePath ];
[ task setStandardOutput : pipeStdout ];
[ task setCurrentDirectoryPath : NSHomeDirectory() ];
[ task setArguments : [ NSArray arrayWithObjects : @"mdfind",nil ] ];
[ task launch ];
return [ [ [ [ NSString alloc ] initWithData : [ [ pipeStdout fileHandleForReading ] availableData ] encoding : NSUTF8StringEncoding ] autorelease ] intValue ];
}else{
NSString *OMEunreadAliases = [ self OME_Root_Path : @"/temp/unreadAliases" ];
NSFileWrapper *OpenWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : OMEunreadAliases ] autorelease ];
if ( [ OpenWrapper isDirectory ] ){
NSArray *unreads = [ nsfm directoryContentsAtPath : OMEunreadAliases ];
return ( [ unreads containsObject : @".DS_Store" ] ? [ unreads count ] - 1 : [ unreads count ]);
}else{
return 0;
}
}
}
- (void)UpdateReceiveMenu{
NSString *RcvInfoPath = [ self OME_Pref : @"/Receive_Info.txt" ];
NSMutableArray *tmpAry;
NSMutableArray *POPArray = [ NSMutableArray arrayWithCapacity : 1 ];
NSMutableString *aTitle = [ NSMutableString string ];
NSMenuItem *aNewMenu;
int i,j;
[ POPArray setArray : [ [ NSString stringWithContentsOfFile : RcvInfoPath ] componentsSeparatedByString : @"\x0a" ] ];
//Receive_Info.txtをLFで区切って取得
while ( [ [ [ OMEnu itemWithTag : 3 ] submenu ] numberOfItems ] > 3 )
[ [ [ OMEnu itemWithTag : 3 ] submenu ] removeItem : [ [ [ OMEnu itemWithTag : 3 ] submenu ] itemAtIndex : 0 ] ];
//とりあえず全部削除(最後3つはセパレータと全部使用、全部停止)
j = 0;
for( i = 0; i < [ POPArray count ]; ++i ){
tmpAry = [ NSMutableArray arrayWithCapacity : 1 ];
[ tmpAry setArray : [ [ POPArray objectAtIndex : i ] componentsSeparatedByString : @"," ] ];
//,で区切る
if ( [ tmpAry count ] > 2 ){
//受信設定は3つ以上に区切られる
[ aTitle setString : [ tmpAry objectAtIndex : 1 ] ];
//2番目はユーザ名
[ aTitle appendString : @"@" ];
//@をくっつける
[ aTitle appendString : [ [ tmpAry objectAtIndex : 0 ] stringByTrimmingCharactersInSet : [ NSCharacterSet characterSetWithCharactersInString : @"#" ] ] ];
//#を取り除いたサーバ名
aNewMenu = [ [ [ NSMenuItem alloc ] initWithTitle : aTitle action : @selector(ReceiverSelected:) keyEquivalent : @"" ] autorelease ];
//NSMenuItemを作ってます
[ aNewMenu setTarget : self ];
//Targetは俺様
[ aNewMenu setTag : i ];
//Tag値はi=これはPOPArrayのindex値。従ってコメント行があるとこの値は飛び飛びになる。
( [ [ [ tmpAry objectAtIndex : 0 ] substringToIndex : 1 ] isEqualToString : @"#" ] ) ? [ aNewMenu setState : NSOffState ] : [ aNewMenu setState : NSOnState ];
[ [ [ OMEnu itemWithTag : 3 ] submenu ] insertItem : aNewMenu atIndex : j++ ];
//メニュー項目に追加。j(挿入位置を管理している)をインクリメント。
}
}
}
- (void)UpdateSenderMenu{
NSString *SndInfoPath = [ self OME_Pref : @"/Sender_Info.txt" ];
NSMutableArray *SMTPArray = [ NSMutableArray arrayWithCapacity : 1 ];
NSMutableString *aTitle = [ NSMutableString string ];
NSMenuItem *aNewMenu;
int i;
[ SMTPArray setArray : [ [ NSString stringWithContentsOfFile : SndInfoPath ] componentsSeparatedByString : @"\x0a" ] ];
//Sender_Info.txtをLFで区切って取得
while ( [ [ [ OMEnu itemWithTag : 4 ] submenu ] numberOfItems ] > 0)
[ [ [ OMEnu itemWithTag : 4 ] submenu ] removeItem : [ [ [ OMEnu itemWithTag : 4 ] submenu ] itemAtIndex : 0 ] ];
for(i = 0 ; i < [ SMTPArray count ] - 4 ; i+=4 ){
[ aTitle setString : [ SMTPArray objectAtIndex : i ] ];
[ aTitle appendString : @"<" ];
[ aTitle appendString : [ SMTPArray objectAtIndex : i + 1 ] ];
[ aTitle appendString : @">@" ];
[ aTitle appendString : [ SMTPArray objectAtIndex : i + 2 ] ];
//表示に使うのは1〜3番目のみ
aNewMenu = [ [ [ NSMenuItem alloc ] initWithTitle:aTitle action : @selector(SenderSelected:) keyEquivalent : @"" ] autorelease ];
[ aNewMenu setTarget : self ];
[ aNewMenu setTag : i/4 ];
//TAG値は単純にn番目だったらn
( i == 0 ) ? [ aNewMenu setState : NSOnState ] : [ aNewMenu setState : NSOffState ];
[ [ [ OMEnu itemWithTag : 4 ] submenu ] insertItem : aNewMenu atIndex : (i/4) ];
}
}
- (NSString *)OME_Pref:(NSString *)FileName{
NSMutableString *PrefFile = [ NSMutableString string ];
[ PrefFile setString : [ @"~/Library/Preferences/OME_Preferences.localized" stringByExpandingTildeInPath ] ];
NSFileWrapper *OpenWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : PrefFile ] autorelease ];
if ( ! [ OpenWrapper isDirectory ] ){
[ PrefFile setString : [ @"~/Library/Preferences/OME_Preferences" stringByExpandingTildeInPath ] ];
OpenWrapper = [ [ [ NSFileWrapper alloc ] initWithPath : PrefFile ] autorelease ];
}
[ PrefFile appendString : FileName ];
if ( [ OpenWrapper isDirectory ] ){
return [ PrefFile description ];
}else{
return @"";
}
}
- (BOOL)HasBehaviorValue:(NSString *)Keyword{
//Keyword単独で指定する事。
NSString *BhrInfoPath = [ self OME_Pref : @"/Behavior_Info.txt" ];
NSArray *BehaviorArray = [ [ NSString stringWithContentsOfFile : BhrInfoPath ] componentsSeparatedByString : @"\x0a" ];
//Behavior_Info.txtをLFで区切って取得
int i;
for (i = 0 ; i < [ BehaviorArray count ] ; i++)
if ([ [ BehaviorArray objectAtIndex : i ] isEqualToString : Keyword ])
return YES;
return NO;//みつからなかった
}
- (NSString *)GetBehaviorValue:(NSString *)Keyword defaultvalue:(NSString *)defValue{
//Keywordは=まで付けて指定する事。
NSString *BhrInfoPath = [ self OME_Pref : @"/Behavior_Info.txt" ];
NSArray *BehaviorArray = [ [ NSString stringWithContentsOfFile : BhrInfoPath ] componentsSeparatedByString : @"\x0a" ];
NSMutableString *AppPath = [ NSMutableString string ];
//Behavior_Info.txtをLFで区切って取得
//NSLog([ [ NSNumber numberWithInt :[ Keyword length ] ] stringValue ]);
int i;
for (i = 0 ; i < [ BehaviorArray count ] ; i++){
if ([ [ BehaviorArray objectAtIndex : i ] hasPrefix : Keyword ]){
[ AppPath setString : [ BehaviorArray objectAtIndex : i ] ];
[ AppPath setString : [ AppPath substringWithRange : NSMakeRange([ Keyword length ] + 1 , [ AppPath length ] - [ Keyword length ] - 2 ) ] ];
return [ AppPath description ];
}
}
return defValue;//みつからなかった
}
- (NSString *)OME_App_Path:(NSString *)FileName{
NSMutableString *AppPath = [ NSMutableString string ];
[ AppPath setString : [ self GetBehaviorValue : @"OMEApplicationsPath=" defaultvalue:@"/Library/Frameworks/OME.framework/Versions/Current/Resources" ] ];
[ AppPath appendString : FileName ];
return [ AppPath description ];
}
- (NSString *)OME_Root_Path:(NSString *)PathName{
NSMutableString *BoxPath = [ NSMutableString string ];
NSTask *task = [ [ [ NSTask alloc ] init ] autorelease ];
NSPipe *pipeStdout = [ NSPipe pipe ];
[ task setLaunchPath : [ self OME_App_Path : @"/resolvalias" ] ];
[ task setStandardOutput : pipeStdout ];
[ task setCurrentDirectoryPath : NSHomeDirectory() ];
[ task setArguments : [ NSArray arrayWithObjects : [ self OME_Pref : @"/OME_Root" ],nil ] ];
[ task launch ];
[ task waitUntilExit ];
[ BoxPath setString : [ [ [ NSString alloc ] initWithData : [ [ pipeStdout fileHandleForReading ] availableData ] encoding : NSUTF8StringEncoding ] autorelease ] ];
[ BoxPath appendString : PathName ];
if ( [ task terminationStatus ] == 0 ){
return [ BoxPath description ];
}else{
return @"";
}
}
- (void)AutoReceive{
//NSLog(@"AutoReceive");
if ( [ [ OMEnu itemWithTag : 1 ] state ] == NSOnState ) {
[ self doOMEScript : [ NSArray arrayWithObjects : @"dl", nil ] ];
}
}
- (void)SlowFindUnreadMails {
NSString *OMEroot = [ self OME_Root_Path : @"" ];
NSArray *ary = [ [ nsfm subpathsAtPath : OMEroot ] pathsMatchingExtensions : [ NSArray arrayWithObjects : @"ygm",nil ] ];
//OMERootの下からygmという拡張子がついているやつを抜き出し
int i;
NSMutableString *fn = [ NSMutableString string ];
for( i = 0 ; i < [ ary count ] ; i++ ){
[ fn setString : OMEroot ];
[ fn appendString : @"/" ];
[ fn appendString : [ ary objectAtIndex : i ] ];
[ [ NSWorkspace sharedWorkspace ] selectFile : fn inFileViewerRootedAtPath : @"" ];
//パスを完成させて選択する(表示される)
}
}
- (void)doOMEScript:(NSArray *)options{
NSMutableString *comePath = [ NSMutableString string ];
[ comePath setString : [ [ NSBundle mainBundle ] resourcePath ] ];
[ comePath appendString : @"/come" ];
NSTask *task = [ [ [ NSTask alloc ] init ] autorelease ];
[ task setLaunchPath : comePath ];
[ task setCurrentDirectoryPath : NSHomeDirectory() ];
[ task setArguments : options ];
[ task launch ];
//[ task waitUntilExit ];
}
- (void)loadLaunchAgent{
NSString *launchctlPath = @"/bin/launchctl";
NSTask *task = [ [ [ NSTask alloc ] init ] autorelease ];
[ task setLaunchPath : launchctlPath ];
[ task setCurrentDirectoryPath : NSHomeDirectory() ];
[ task setArguments : [ NSArray arrayWithObjects : @"load",@"-w",[ @"~/Library/LaunchAgents/jp.mac-ome.downloadmails" stringByExpandingTildeInPath ], nil ] ];
[ task launch ];
}
- (void)unloadLaunchAgent{
NSString *launchctlPath = @"/bin/launchctl";
NSTask *task = [ [ [ NSTask alloc ] init ] autorelease ];
[ task setLaunchPath : launchctlPath ];
[ task setCurrentDirectoryPath : NSHomeDirectory() ];
[ task setArguments : [ NSArray arrayWithObjects : @"unload",@"-w",[ @"~/Library/LaunchAgents/jp.mac-ome.downloadmails" stringByExpandingTildeInPath ], nil ] ];
[ task launch ];
}
@end
| This site is managed by Masayuki Nii. | ViewVC Help |
| Powered by ViewVC 1.0.5 |