Author: rmottola
Date: Wed Apr 30 18:56:58 2014
New Revision: 37821

URL: http://svn.gna.org/viewcvs/gnustep?rev=37821&view=rev
Log:
Try to guess the best of [NSHost names] and not just name.

Modified:
    apps/gworkspace/trunk/ChangeLog
    apps/gworkspace/trunk/FSNode/FSNIcon.m

Modified: apps/gworkspace/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/ChangeLog?rev=37821&r1=37820&r2=37821&view=diff
==============================================================================
--- apps/gworkspace/trunk/ChangeLog     (original)
+++ apps/gworkspace/trunk/ChangeLog     Wed Apr 30 18:56:58 2014
@@ -1,3 +1,8 @@
+2014-04-30 Riccardo Mottola <[email protected]>
+
+       * FSNode/FSNIcon.m
+       Try to guess the best of [NSHost names] and not just name.
+
 2013-12-18 Riccardo Mottola <[email protected]>
 
        * Recycler/RecyclerIcon.m

Modified: apps/gworkspace/trunk/FSNode/FSNIcon.m
URL: 
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/FSNode/FSNIcon.m?rev=37821&r1=37820&r2=37821&view=diff
==============================================================================
--- apps/gworkspace/trunk/FSNode/FSNIcon.m      (original)
+++ apps/gworkspace/trunk/FSNode/FSNIcon.m      Wed Apr 30 18:56:58 2014
@@ -1,6 +1,6 @@
 /* FSNIcon.m
  *  
- * Copyright (C) 2004-2013 Free Software Foundation, Inc.
+ * Copyright (C) 2004-2014 Free Software Foundation, Inc.
  *
  * Author: Enrico Sersale <[email protected]>
  * Date: March 2004
@@ -94,6 +94,51 @@
   return branchImage;
 }
 
+/* we try to find a good host name.
+ * We try to find something different from localhost, if possibile without 
dots,
+ * else the first part of the qualified hostname gets taken */
++ (NSString *)getBestHostName
+{
+  NSHost *host = [NSHost currentHost];
+  NSString *hname;
+  NSRange range;
+  NSArray *hnames;
+
+  hnames = [host names];
+  if ([hnames count] > 0)
+    {
+      hname = [hnames objectAtIndex:0];
+
+      if ([hnames count] > 1)
+        {
+          NSUInteger i;
+
+          for (i = 0; i < [hnames count]; i++)
+            {
+              NSString *better;
+
+              better = [hnames objectAtIndex:i];
+              if (![better isEqualToString:@"localhost"])
+                {
+                  if ([hname isEqualToString:@"localhost"] || [hname 
isEqualToString:@"127.0.0.1"])
+                    hname = better;
+                  else if ([better rangeOfString:@"."].location == NSNotFound)
+                    hname = better;
+                }
+            }
+        }
+
+      range = [hname rangeOfString: @"."];
+      if (range.length != 0)
+        hname = [hname substringToIndex: range.location];
+    }
+  else
+    {
+      hname = @"unknown";
+    }
+  return hname;
+}
+
 - (id)initForNode:(FSNode *)anode
      nodeInfoType:(FSNInfoType)type
      extendedType:(NSString *)exttype
@@ -144,17 +189,13 @@
     hlightRect = NSIntegralRect(hlightRect);
     ASSIGN (highlightPath, [fsnodeRep highlightPathOfSize: hlightRect.size]);
         
-               if ([[node path] isEqual: path_separator()] && ([node 
isMountPoint] == NO)) {
-                 NSHost *host = [NSHost currentHost];
-                 NSString *hname = [host name];
-                 NSRange range = [hname rangeOfString: @"."];
-
-                 if (range.length != 0) {      
-                         hname = [hname substringToIndex: range.location];
-                 }                     
-      
-                 ASSIGN (hostname, hname);
-               } 
+    if ([[node path] isEqual: path_separator()] && ([node isMountPoint] == NO))
+      {
+       NSString *hname;
+
+       hname = [FSNIcon getBestHostName];
+        ASSIGN (hostname, hname);
+      } 
     
     label = [FSNTextCell new];
     [label setFont: lfont];
@@ -731,17 +772,13 @@
   drawicon = icon;
   DESTROY (selectedicon);
   
-  if ([[node path] isEqual: path_separator()] && ([node isMountPoint] == NO)) {
-    NSHost *host = [NSHost currentHost];
-    NSString *hname = [host name];
-    NSRange range = [hname rangeOfString: @"."];
-
-    if (range.length != 0) {   
-      hname = [hname substringToIndex: range.location];
-    }                  
-      
-    ASSIGN (hostname, hname);
-  } 
+  if ([[node path] isEqual: path_separator()] && ([node isMountPoint] == NO))
+    { 
+      NSString *hname;
+
+      hname = [FSNIcon getBestHostName];
+      ASSIGN (hostname, hname);
+    } 
   
   if (extInfoType) {
     [self setExtendedShowType: extInfoType];


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to