From patchwork Tue Mar 15 19:02:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 8591851 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5D2DAC0553 for ; Tue, 15 Mar 2016 19:03:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A5B98203AA for ; Tue, 15 Mar 2016 19:03:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F0100203A9 for ; Tue, 15 Mar 2016 19:03:07 +0000 (UTC) Received: from localhost ([::1]:50879 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afuFH-0003MA-5u for patchwork-qemu-devel@patchwork.kernel.org; Tue, 15 Mar 2016 15:03:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afuFA-0003Lz-Mw for qemu-devel@nongnu.org; Tue, 15 Mar 2016 15:03:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afuF7-0001G9-Gw for qemu-devel@nongnu.org; Tue, 15 Mar 2016 15:03:00 -0400 Received: from mail-io0-x235.google.com ([2607:f8b0:4001:c06::235]:34739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afuF7-0001F1-Bh for qemu-devel@nongnu.org; Tue, 15 Mar 2016 15:02:57 -0400 Received: by mail-io0-x235.google.com with SMTP id m184so35995193iof.1 for ; Tue, 15 Mar 2016 12:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-transfer-encoding:subject:date:message-id:cc:to :mime-version; bh=OR0C7rK0Ncw/jIbJD9eOCHbeVouRdp0oPrEr+W9X5So=; b=hrlPurhbVLmMbH4L0sOMBlJa2EK0G8TGdKT7/Y0hukc8YWO3RxM4kmQZLiSkUQZMyX SELQ0TlAljPKRhPWwzHFHLTWxcDOOv9Lxv+Xo9tEIMeF24nHKzHKNVeEWCTcNOl5FNX4 3oFIeBAamz2X+ar4kQInw1wirysVCBgdv540WcKCF4MfoG0J31nhlE5/AHIxHY/4MM7P tcoX1F0p4TiayCN6jvrullazLDKA4FbSn2gT0NEyOVbVpujw9i+8jVXXWavq6Ub5/GNG USEq1bn4f8ZrA1kL99YsYWRODxflyQpjnNQI9AvjMrciMdROWiKEf8NN8rxQngHwn/94 2D0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-transfer-encoding:subject:date :message-id:cc:to:mime-version; bh=OR0C7rK0Ncw/jIbJD9eOCHbeVouRdp0oPrEr+W9X5So=; b=LhYxz4cynC/OV6xt4ItCIh8q/gJmrUzElUteyHn8mKhaWMx5a8+Ynv5lZpSaKXwgMh e4JcFQso275f710x0kdNZxHAH72YyUfLWso5Q+QNgUOYDuQo5WFmgKRFgFWLDn5fj5R3 M5xftdgi1r6lwh6p/amCsxMulFtjKsfOOGn/JN0FMKAj9Evd8L/WHUzmga4AUjuD3FEA 4C27RpSCsxNAzjUdhC1vQ1TkjlNpWtxbMgXIGvtLEB7rspwyFkh9VzdzAbl2o4/nVheJ Doaus+jwK9QcVWc3DuHPyJLQGNAzU0GXqYx9nyNqiT9AO4lD5jSwbSU4WfDnqNLGLUAk IEeA== X-Gm-Message-State: AD7BkJJZg9qnHYh88y/iTTsNrJqP9PWAB/v1OHRJL6s83sEeT4nMoC/hzJZ2oht4q6WLAA== X-Received: by 10.107.17.31 with SMTP id z31mr275207ioi.97.1458068576783; Tue, 15 Mar 2016 12:02:56 -0700 (PDT) Received: from [192.168.0.5] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id l9sm29575ioa.35.2016.03.15.12.02.55 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Mar 2016 12:02:55 -0700 (PDT) From: Programmingkid Date: Tue, 15 Mar 2016 15:02:54 -0400 Message-Id: To: Peter Maydell Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::235 Cc: qemu-devel qemu-devel Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: fix help menus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MIME_QP_LONG_LINE, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the help menus actually work. The code will search thru three different locations for the help file. If it can't be found a dialog will tell the user the file can't be found. Signed-off-by: John Arbuckle --- *v3 changes Removed code that opens a web page. Removed number_of_paths and added ARRAY_SIZE() macro. *v2 changes Moved opening code to one method. Searches three different locations on the user's computer first. Attempts to open file on web if file can't be found on user's computer. ui/cocoa.m | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 7063a02..9295233 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -858,6 +858,7 @@ QemuCocoaView *cocoaView; - (void)ejectDeviceMedia:(id)sender; - (void)changeDeviceMedia:(id)sender; - (BOOL)verifyQuit; +- (void)openDocumentation:(NSString *)filename; @end @implementation QemuCocoaAppController @@ -994,20 +995,42 @@ QemuCocoaView *cocoaView; [cocoaView toggleFullScreen:sender]; } +/* Tries to find then open the specified filename */ +- (void) openDocumentation: (NSString *) filename +{ + /* Where to look for local files */ + NSString *path_array[] = {@"../share/doc/qemu/", @"../doc/qemu/", @"../"}; + NSString *full_file_path; + + /* iterate thru the possible paths until the file is found */ + int index; + for (index = 0; index < ARRAY_SIZE(path_array); index++) { + full_file_path = [[NSBundle mainBundle] executablePath]; + full_file_path = [full_file_path stringByDeletingLastPathComponent]; + full_file_path = [NSString stringWithFormat: @"%@/%@%@", full_file_path, + path_array[index], filename]; + if ([[NSWorkspace sharedWorkspace] openFile: full_file_path] == YES) { + return; + } + } + + /* If none of the paths opened a file */ + NSBeep(); + QEMU_Alert(@"Failed to open file"); +} + - (void)showQEMUDoc:(id)sender { COCOA_DEBUG("QemuCocoaAppController: showQEMUDoc\n"); - [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-doc.html", - [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"]; + [self openDocumentation: @"qemu-doc.html"]; } - (void)showQEMUTec:(id)sender { COCOA_DEBUG("QemuCocoaAppController: showQEMUTec\n"); - [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", - [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"]; + [self openDocumentation: @"qemu-tech.html"]; } /* Stretches video to fit host monitor size */