1 18 package com.izforge.izpack.panels; 19 20 import com.izforge.izpack.ExecutableFile; 21 import com.izforge.izpack.Pack; 22 import com.izforge.izpack.gui.ButtonFactory; 23 import com.izforge.izpack.gui.LabelFactory; 24 import com.izforge.izpack.installer.*; 25 import com.izforge.izpack.util.*; 26 import com.izforge.izpack.util.os.Shortcut; 27 import com.izforge.izpack.util.os.unix.UnixHelper; 28 import com.izforge.izpack.util.xml.XMLHelper; 29 import net.n3.nanoxml.*; 30 31 import javax.swing.*; 32 import javax.swing.border.Border ; 33 import javax.swing.border.EmptyBorder ; 34 import javax.swing.border.TitledBorder ; 35 import javax.swing.event.ListSelectionEvent ; 36 import javax.swing.event.ListSelectionListener ; 37 import java.awt.*; 38 import java.awt.event.ActionEvent ; 39 import java.awt.event.ActionListener ; 40 import java.io.File ; 41 import java.io.FileWriter ; 42 import java.io.InputStream ; 43 import java.util.ArrayList ; 44 import java.util.Enumeration ; 45 import java.util.Vector ; 46 47 50 51 52 61 public class ShortcutPanel extends IzPanel implements ActionListener , ListSelectionListener 64 { 65 66 68 private static final long serialVersionUID = 3256722870838112311L; 69 70 72 73 public final static String SPEC_ATTRIBUTE_KDE_USERNAME ="KdeUsername"; 74 75 76 public final static String SPEC_ATTRIBUTE_KDE_SUBST_UID = "KdeSubstUID"; 77 78 79 public final static String SPEC_ATTRIBUTE_URL = "url"; 80 81 82 public final static String SPEC_ATTRIBUTE_TYPE = "type"; 83 84 85 public final static String SPEC_ATTRIBUTE_TERMINAL_OPTIONS = "terminalOptions"; 86 87 88 public final static String SPEC_ATTRIBUTE_TERMINAL = "terminal"; 89 90 91 public final static String SPEC_ATTRIBUTE_MIMETYPE = "mimetype"; 92 93 94 public final static String SPEC_ATTRIBUTE_ENCODING = "encoding"; 95 96 97 private static final String LOCATION_APPLICATIONS = "applications"; 98 99 100 private static final String LOCATION_START_MENU = "startMenu"; 101 102 103 public static final String SPEC_CATEGORIES = "categories"; 104 105 106 public static final String SPEC_TRYEXEC = "tryexec"; 107 108 109 113 private static final String SEPARATOR_LINE = "--------------------------------------------------------------------------------"; 114 115 120 private static final String TEXT_FILE_NAME = "Shortcuts.txt"; 121 122 125 private static final String SPEC_FILE_NAME = "shortcutSpec.xml"; 126 127 131 132 private static final String SPEC_KEY_SKIP_IFNOT_SUPPORTED = "skipIfNotSupported"; 133 134 135 private static final String SPEC_KEY_NOT_SUPPORTED = "notSupported"; 136 137 138 private static final String SPEC_KEY_PROGRAM_GROUP = "programGroup"; 139 140 141 private static final String SPEC_KEY_SHORTCUT = "shortcut"; 142 143 144 private static final String SPEC_KEY_PACKS = "createForPack"; 145 146 150 private static final String SPEC_ATTRIBUTE_DEFAULT_GROUP = "defaultName"; 151 152 154 private static final String SPEC_ATTRIBUTE_INSTALLGROUP = "installGroup"; 155 156 157 private static final String SPEC_ATTRIBUTE_LOCATION = "location"; 158 159 160 private static final String SPEC_ATTRIBUTE_NAME = "name"; 161 162 163 private static final String SPEC_ATTRIBUTE_SUBGROUP = "subgroup"; 164 165 166 private static final String SPEC_ATTRIBUTE_DESCRIPTION = "description"; 167 168 169 private static final String SPEC_ATTRIBUTE_TARGET = "target"; 170 171 172 private static final String SPEC_ATTRIBUTE_COMMAND = "commandLine"; 173 174 175 private static final String SPEC_ATTRIBUTE_ICON = "iconFile"; 176 177 178 private static final String SPEC_ATTRIBUTE_ICON_INDEX = "iconIndex"; 179 180 181 private static final String SPEC_ATTRIBUTE_WORKING_DIR = "workingDirectory"; 182 183 184 private static final String SPEC_ATTRIBUTE_INITIAL_STATE = "initialState"; 185 186 187 private static final String SPEC_ATTRIBUTE_DESKTOP = "desktop"; 188 189 190 private static final String SPEC_ATTRIBUTE_APPLICATIONS = "applications"; 191 192 193 private static final String SPEC_ATTRIBUTE_START_MENU = "startMenu"; 194 195 196 private static final String SPEC_ATTRIBUTE_STARTUP = "startup"; 197 198 199 private static final String SPEC_ATTRIBUTE_PROGRAM_GROUP = "programGroup"; 200 201 205 206 private static final String SPEC_VALUE_APPLICATIONS = "applications"; 207 208 209 private static final String SPEC_VALUE_START_MENU = "startMenu"; 210 211 212 private static final String SPEC_VALUE_NO_SHOW = "noShow"; 213 214 215 private static final String SPEC_VALUE_NORMAL = "normal"; 216 217 218 private static final String SPEC_VALUE_MAXIMIZED = "maximized"; 219 220 221 private static final String SPEC_VALUE_MINIMIZED = "minimized"; 222 223 227 228 public static final String AUTO_KEY_PROGRAM_GROUP = SPEC_KEY_PROGRAM_GROUP; 229 230 231 public static final String AUTO_KEY_SHORTCUT = SPEC_KEY_SHORTCUT; 232 233 237 238 public static final String AUTO_ATTRIBUTE_NAME = "name"; 239 240 241 public static final String AUTO_ATTRIBUTE_GROUP = "group"; 242 243 244 public static final String AUTO_ATTRIBUTE_TYPE = "type"; 245 246 247 public static final String AUTO_ATTRIBUTE_COMMAND = "commandLine"; 248 249 250 public static final String AUTO_ATTRIBUTE_DESCRIPTION = "description"; 251 252 253 public static final String AUTO_ATTRIBUTE_ICON = "icon"; 254 255 256 public static final String AUTO_ATTRIBUTE_ICON_INDEX = "iconIndex"; 257 258 259 public static final String AUTO_ATTRIBUTE_INITIAL_STATE = "initialState"; 260 261 262 public static final String AUTO_ATTRIBUTE_TARGET = "target"; 263 264 265 public static final String AUTO_ATTRIBUTE_WORKING_DIR = "workingDirectory"; 266 267 269 270 public static final String CREATE_FOR_ALL = "createForAll"; 271 272 private static ShortcutPanel self = null; 273 274 275 static boolean create; 276 277 282 public static boolean createImmediately = true; 283 284 285 private static boolean isRootUser; 286 287 289 291 292 private Vector execFiles = new Vector (); 293 294 298 299 private JLabel listLabel; 300 301 302 private JList groupList; 303 304 305 private JList targetList; 306 307 311 private JTextField programGroup; 312 313 314 private JButton defaultButton; 315 316 317 private JButton saveButton; 318 319 322 private JCheckBox allowDesktopShortcut; 323 324 325 private JCheckBox createShortcuts; 326 327 328 private JRadioButton currentUser; 329 330 331 private JRadioButton allUsers; 332 333 334 private GridBagLayout layout; 335 336 337 private GridBagConstraints constraints; 338 339 342 private String suggestedProgramGroup; 343 344 345 private String groupName; 346 347 353 private int groupLocation; 354 355 356 private XMLElement spec; 357 358 359 private boolean hasDesktopShortcuts = false; 360 361 362 private boolean skipIfNotSupported = false; 363 364 365 private Shortcut shortcut; 366 367 371 private Vector shortcuts = new Vector (); 372 373 378 private Vector files = new Vector (); 379 380 384 private boolean shortcutsToCreate = false; 385 386 387 private boolean haveShortcutSpec = false; 388 389 393 private boolean simulteNotSupported = false; 394 395 396 397 private File itsProgramFolder; 399 400 401 private int itsUserType; 402 403 404 public final static String USER_TYPE = "usertype"; 405 406 407 private Vector shortCuts; 408 409 410 int line; 411 412 413 int col; 414 415 417 419 422 423 429 430 433 public ShortcutPanel(InstallerFrame parent, InstallData installData) 434 { 435 super(parent, installData, "link16x16"); 436 437 layout = (GridBagLayout) super.getLayout(); 438 Object con = getLayoutHelper().getDefaultConstraints(); 439 if( con instanceof GridBagConstraints) 440 constraints = (GridBagConstraints) con; 441 else 442 con = new GridBagConstraints(); 443 setLayout(super.getLayout()); 444 445 if( self != null ) 446 throw new RuntimeException ( this.getClass().getName() + " is not allowed to instantiate more than once!" ); 447 448 self = this; 449 } 450 451 453 456 457 458 463 464 465 public void actionPerformed(ActionEvent event) 466 { 467 Object eventSource = event.getSource(); 468 469 473 474 if (eventSource.equals(currentUser)) 480 { 481 groupList.setListData(shortcut.getProgramGroups(Shortcut.CURRENT_USER)); 482 programGroup.setText(suggestedProgramGroup); 483 shortcut.setUserType(itsUserType = Shortcut.CURRENT_USER); 484 485 return; 486 } 487 488 else if (eventSource.equals(allUsers)) 494 { 495 groupList.setListData(shortcut.getProgramGroups(Shortcut.ALL_USERS)); 496 programGroup.setText(suggestedProgramGroup); 497 shortcut.setUserType(itsUserType = Shortcut.ALL_USERS); 498 499 return; 500 } 501 502 else if (eventSource.equals(defaultButton)) 510 { 511 groupList.getSelectionModel().clearSelection(); 512 programGroup.setText(suggestedProgramGroup); 513 514 return; 515 } 516 517 else if (eventSource.equals(saveButton)) 522 { 523 saveToFile(); 524 525 addToUninstaller(); 527 528 return; 529 } 530 else if (eventSource.equals(createShortcuts)) 531 { 532 create = createShortcuts.isSelected(); 533 534 if (groupList != null) 535 { 536 groupList.setEnabled(create); 537 } 538 539 programGroup.setEnabled(create); 540 currentUser.setEnabled(create); 541 defaultButton.setEnabled(create); 542 543 if (allowDesktopShortcut != null) 545 { 546 allowDesktopShortcut.setEnabled(create); 547 } 548 549 if (isRootUser) 550 { 551 allUsers.setEnabled(create); 552 } 553 } 554 } 555 556 557 558 564 565 566 public boolean isValidated() 567 { 568 try 569 { 570 groupName = programGroup.getText(); 571 } 572 catch (Throwable exception) 573 { 574 groupName = ""; 575 } 576 577 create = createShortcuts.isSelected(); 578 579 if (createImmediately){ 580 createAndRegisterShortcuts(); 581 } 582 583 return (true); 584 } 585 586 587 588 591 592 593 public void panelActivate() 594 { 595 try 596 { 597 readShortcutSpec(); 598 } 599 catch (Throwable exception) 600 { 601 System.out.println("could not read shortcut spec!"); 602 exception.printStackTrace(); 603 } 604 605 try 607 { 608 shortcut = (Shortcut) (TargetFactory.getInstance() 609 .makeObject("com.izforge.izpack.util.os.Shortcut")); 610 shortcut.initialize(Shortcut.APPLICATIONS, "-"); 611 } 612 catch (Throwable exception) 613 { 614 System.out.println("could not create shortcut instance"); 615 exception.printStackTrace(); 616 } 617 618 analyzeShortcutSpec(); 619 620 if (shortcutsToCreate && !OsVersion.IS_OSX) 621 { 622 if (shortcut.supported() && !simulteNotSupported) 623 { 624 File allUsersProgramsFolder = getProgramsFolder(Shortcut.ALL_USERS); 625 626 Debug.log("All UsersProgramsFolder: '" + allUsersProgramsFolder + "'"); 627 628 File forceTest = new File(allUsersProgramsFolder + File.separator 629 + System.getProperty("user.name") + System.currentTimeMillis()); 630 631 try 632 { 633 isRootUser = forceTest.createNewFile(); 634 } 635 catch (Exception e) 636 { 637 isRootUser = false; 638 Debug.log("IOException: " + "'" + e.getLocalizedMessage() + "'"); 639 Debug.log("You cannot create '" + forceTest + "'"); 640 641 } 642 643 if (forceTest.exists()) 644 { 645 Debug.log("Delete temporary File: '" + forceTest + "'"); 646 forceTest.delete(); 647 } 648 649 String perm = isRootUser ? "can" : "cannot"; 650 651 Debug.log("You " + perm + " write into '" + allUsersProgramsFolder + "'"); 652 653 if (isRootUser) 654 { 655 itsUserType = Shortcut.ALL_USERS; 656 } 657 else 658 { 659 itsUserType = Shortcut.CURRENT_USER; 660 } 661 662 buildUI(getProgramsFolder(isRootUser ? Shortcut.ALL_USERS : Shortcut.CURRENT_USER)); 663 664 } 670 else 671 { 672 buildAlternateUI(); 674 675 } 678 } 679 else 680 { 681 parent.skipPanel(); 683 } 684 } 685 686 693 private File getProgramsFolder(int userType) 694 { 695 String path = shortcut.getProgramsFolder(userType); 696 697 return (new File(path)); 698 699 } 713 714 720 721 722 public void valueChanged(ListSelectionEvent event) 723 { 724 if (programGroup == null) { return; } 725 726 String value = ""; 727 728 try 729 { 730 value = (String ) groupList.getSelectedValue(); 731 } 732 catch (ClassCastException exception) 733 {} 734 735 if (value == null) 736 { 737 value = ""; 738 } 739 740 programGroup.setText(value + File.separator + suggestedProgramGroup); 741 } 742 743 744 745 750 751 752 private void readShortcutSpec() throws Exception 753 { 754 InputStream input = null; 756 757 try 758 { 759 input = parent.getResource(TargetFactory.getCurrentOSPrefix() + SPEC_FILE_NAME); 760 } 761 catch (ResourceNotFoundException rnfE) 762 { 763 input = parent.getResource(SPEC_FILE_NAME); 764 } 765 766 if (input == null) 767 { 768 haveShortcutSpec = false; 769 770 return; 771 } 772 773 VariableSubstitutor substitutor = new VariableSubstitutor(idata.getVariables()); 780 781 String substitutedSpec = substitutor.substitute(input, "xml"); 783 784 793 StdXMLParser parser = new StdXMLParser(); 794 parser.setBuilder(new StdXMLBuilder()); 795 parser.setValidator(new NonValidator()); 796 parser.setReader(StdXMLReader.stringReader(substitutedSpec)); 797 798 spec = (XMLElement) parser.parse(); 800 801 input.close(); 803 haveShortcutSpec = true; 804 } 805 806 807 808 812 813 814 private void analyzeShortcutSpec() 815 { 816 if (!haveShortcutSpec) 817 { 818 shortcutsToCreate = false; 819 820 return; 821 } 822 823 XMLElement skipper = spec.getFirstChildNamed(SPEC_KEY_SKIP_IFNOT_SUPPORTED); 824 skipIfNotSupported = (skipper != null); 825 826 XMLElement support = spec.getFirstChildNamed(SPEC_KEY_NOT_SUPPORTED); 831 832 if (support != null) 833 { 834 simulteNotSupported = true; 835 } 836 837 843 XMLElement group = null; 844 Vector groupSpecs = spec.getChildrenNamed(SPEC_KEY_PROGRAM_GROUP); 845 String selectedInstallGroup = idata.getVariable("INSTALL_GROUP"); 846 if (selectedInstallGroup!=null){ 847 for (int i = 0; i < groupSpecs.size(); i++) 851 { 852 XMLElement g = (XMLElement)groupSpecs.get(i); 853 String instGrp = g.getAttribute(SPEC_ATTRIBUTE_INSTALLGROUP); 854 if (instGrp!=null && selectedInstallGroup.equalsIgnoreCase(instGrp)){ 855 group = g; 856 break; 857 } 858 } 859 } 860 if (group==null){ 861 group = spec.getFirstChildNamed(SPEC_KEY_PROGRAM_GROUP); 863 } 864 865 String location = null; 866 hasDesktopShortcuts = false; 867 868 if (group != null) 869 { 870 suggestedProgramGroup = group.getAttribute(SPEC_ATTRIBUTE_DEFAULT_GROUP, ""); 871 location = group.getAttribute(SPEC_ATTRIBUTE_LOCATION, SPEC_VALUE_APPLICATIONS); 872 } 873 else 874 { 875 suggestedProgramGroup = ""; 876 location = SPEC_VALUE_APPLICATIONS; 877 } 878 879 if (location.equals(SPEC_VALUE_APPLICATIONS)) 880 { 881 groupLocation = Shortcut.APPLICATIONS; 882 } 883 else if (location.equals(SPEC_VALUE_START_MENU)) 884 { 885 groupLocation = Shortcut.START_MENU; 886 } 887 888 Vector shortcutSpecs = spec.getChildrenNamed(SPEC_KEY_SHORTCUT); 894 XMLElement shortcutSpec; 895 ShortcutData data; 896 897 shortCuts = new Vector (); 898 899 for (int i = 0; i < shortcutSpecs.size(); i++) 900 { 901 shortcutSpec = (XMLElement) shortcutSpecs.elementAt(i); 903 904 if (!OsConstraint.oneMatchesCurrentSystem(shortcutSpec)) 905 { 906 continue; 907 } 908 909 if (!checkConditions(shortcutSpec)) 912 { 913 continue; 914 } 915 916 data = new ShortcutData(); 919 920 data.name = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_NAME); 921 data.subgroup = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_SUBGROUP, ""); 922 data.description = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_DESCRIPTION, ""); 923 924 data.deskTopEntryLinux_Encoding = shortcutSpec 926 .getAttribute(SPEC_ATTRIBUTE_ENCODING, ""); 927 data.deskTopEntryLinux_MimeType = shortcutSpec 928 .getAttribute(SPEC_ATTRIBUTE_MIMETYPE, ""); 929 data.deskTopEntryLinux_Terminal = shortcutSpec 930 .getAttribute(SPEC_ATTRIBUTE_TERMINAL, ""); 931 data.deskTopEntryLinux_TerminalOptions = shortcutSpec.getAttribute( 932 SPEC_ATTRIBUTE_TERMINAL_OPTIONS, ""); 933 data.deskTopEntryLinux_Type = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_TYPE, ""); 934 935 data.deskTopEntryLinux_URL = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_URL, ""); 936 937 data.deskTopEntryLinux_X_KDE_SubstituteUID = shortcutSpec.getAttribute( 938 SPEC_ATTRIBUTE_KDE_SUBST_UID, "false"); 939 940 data.deskTopEntryLinux_X_KDE_UserName = shortcutSpec.getAttribute( 941 SPEC_ATTRIBUTE_KDE_USERNAME, "root"); 942 943 data.Categories = shortcutSpec.getAttribute( 944 SPEC_CATEGORIES, "Application;Development"); 945 946 data.TryExec = shortcutSpec.getAttribute( 947 SPEC_TRYEXEC, ""); 948 949 data.createForAll = new Boolean (shortcutSpec.getAttribute(CREATE_FOR_ALL, "false")); 950 951 data.target = fixSeparatorChar(shortcutSpec.getAttribute(SPEC_ATTRIBUTE_TARGET, "")); 954 955 data.commandLine = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_COMMAND, ""); 957 958 data.iconFile = fixSeparatorChar(shortcutSpec.getAttribute(SPEC_ATTRIBUTE_ICON, "")); 960 data.iconIndex = Integer.parseInt(shortcutSpec.getAttribute(SPEC_ATTRIBUTE_ICON_INDEX, 961 "0")); 962 963 data.workingDirectory = fixSeparatorChar(shortcutSpec.getAttribute( 965 SPEC_ATTRIBUTE_WORKING_DIR, "")); 966 967 String initialState = shortcutSpec.getAttribute(SPEC_ATTRIBUTE_INITIAL_STATE, ""); 968 969 if (initialState.equals(SPEC_VALUE_NO_SHOW)) 970 { 971 data.initialState = Shortcut.HIDE; 972 } 973 else if (initialState.equals(SPEC_VALUE_NORMAL)) 974 { 975 data.initialState = Shortcut.NORMAL; 976 } 977 else if (initialState.equals(SPEC_VALUE_MAXIMIZED)) 978 { 979 data.initialState = Shortcut.MAXIMIZED; 980 } 981 else if (initialState.equals(SPEC_VALUE_MINIMIZED)) 982 { 983 data.initialState = Shortcut.MINIMIZED; 984 } 985 else 986 { 987 data.initialState = Shortcut.NORMAL; 988 } 989 990 992 if (data.name == null) 1001 { 1002 continue; 1003 } 1004 1005 if (data.target == null) 1008 { 1009 data.target = ""; 1011 } 1012 1014 Vector forPacks = shortcutSpec.getChildrenNamed(SPEC_KEY_PACKS); 1017 1018 if (!shortcutRequiredFor(forPacks)) 1019 { 1020 continue; 1021 } 1022 { 1035 if (XMLHelper.attributeIsTrue(shortcutSpec, SPEC_ATTRIBUTE_DESKTOP)) 1036 { 1037 hasDesktopShortcuts = true; 1038 data.addToGroup = false; 1039 data.type = Shortcut.DESKTOP; 1040 shortcuts.add(data.clone()); 1041 } 1042 1043 if (XMLHelper.attributeIsTrue(shortcutSpec, SPEC_ATTRIBUTE_APPLICATIONS)) 1044 { 1045 data.addToGroup = false; 1046 data.type = Shortcut.APPLICATIONS; 1047 shortcuts.add(data.clone()); 1048 } 1049 1050 if (XMLHelper.attributeIsTrue(shortcutSpec, SPEC_ATTRIBUTE_START_MENU)) 1051 { 1052 data.addToGroup = false; 1053 data.type = Shortcut.START_MENU; 1054 shortcuts.add(data.clone()); 1055 } 1056 1057 if (XMLHelper.attributeIsTrue(shortcutSpec, SPEC_ATTRIBUTE_STARTUP)) 1058 { 1059 data.addToGroup = false; 1060 data.type = Shortcut.START_UP; 1061 shortcuts.add(data.clone()); 1062 } 1063 1064 if (XMLHelper.attributeIsTrue(shortcutSpec, SPEC_ATTRIBUTE_PROGRAM_GROUP)) 1065 { 1066 data.addToGroup = true; 1067 data.type = Shortcut.APPLICATIONS; 1068 shortcuts.add(data.clone()); 1069 } 1070 1071 shortCuts.add((data.name == null) ? "" : data.name); 1074 } 1076 } 1077 1078 if (shortcuts.size() > 0) 1082 { 1083 shortcutsToCreate = true; 1084 } 1085 } 1086 1087 1094 private boolean checkConditions(XMLElement shortcutSpec) 1095 { 1096 1109 return true; } 1111 1112 1113 1114 1119 public void createAndRegisterShortcuts(){ 1120 createShortcuts(); 1121 addToUninstaller(); 1122 } 1123 1124 1127 1128 1129 private void createShortcuts() 1130 { 1131 if (!create) { Debug.log( this.getClass().getName() + "::createShortcuts():create=" + create ); return; } 1132 1133 ShortcutData data; 1134 1135 String gn = groupName; 1137 1138 for (int i = 0; i < shortcuts.size(); i++) 1139 { 1140 data = (ShortcutData) shortcuts.elementAt(i); 1141 1142 try 1143 { 1144 gn = groupName + data.subgroup; 1145 shortcut.setUserType(itsUserType); 1146 shortcut.setLinkName(data.name); 1147 shortcut.setLinkType(data.type); 1148 shortcut.setArguments(data.commandLine); 1149 shortcut.setDescription(data.description); 1150 shortcut.setIconLocation(data.iconFile, data.iconIndex); 1151 1152 shortcut.setShowCommand(data.initialState); 1153 shortcut.setTargetPath(data.target); 1154 shortcut.setWorkingDirectory(data.workingDirectory); 1155 shortcut.setEncoding(data.deskTopEntryLinux_Encoding); 1156 shortcut.setMimetype(data.deskTopEntryLinux_MimeType); 1157 1158 shortcut.setTerminal(data.deskTopEntryLinux_Terminal); 1159 shortcut.setTerminalOptions(data.deskTopEntryLinux_TerminalOptions); 1160 shortcut.setType(data.deskTopEntryLinux_Type); 1161 shortcut.setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID); 1162 shortcut.setKdeUserName(data.deskTopEntryLinux_X_KDE_UserName); 1163 shortcut.setURL(data.deskTopEntryLinux_URL); 1164 shortcut.setTryExec(data.TryExec); 1165 shortcut.setCategories(data.Categories); 1166 shortcut.setCreateForAll(data.createForAll); 1167 1168 shortcut.setUninstaller( UninstallData.getInstance() ); 1169 1170 if (data.addToGroup) 1171 { 1172 shortcut.setProgramGroup(gn); 1173 } 1174 else 1175 { 1176 shortcut.setProgramGroup(""); 1177 } 1178 1179 try 1180 { 1181 if ((data.type != Shortcut.DESKTOP) 1188 || ((data.type == Shortcut.DESKTOP) && allowDesktopShortcut 1189 .isSelected())) 1190 { 1191 shortcut.save(); 1193 1194 String fileName = shortcut.getFileName(); 1196 files.add(0, fileName); 1197 1198 File file = new File(fileName); 1199 File base = new File(shortcut.getBasePath()); 1200 Vector intermediates = new Vector (); 1201 1202 execFiles.add(new ExecutableFile(fileName, ExecutableFile.UNINSTALL, 1204 ExecutableFile.IGNORE, new ArrayList (), false)); 1205 1206 files.add(fileName); 1207 1208 while ((file = file.getParentFile()) != null) 1209 { 1210 if (file.equals(base)) 1211 { 1212 break; 1213 } 1214 1215 intermediates.add(file); 1216 } 1217 1218 if (file != null) 1219 { 1220 Enumeration filesEnum = intermediates.elements(); 1221 1222 while (filesEnum.hasMoreElements()) 1223 { 1224 files.add(0, filesEnum.nextElement().toString()); 1225 } 1226 } 1227 } 1228 } 1229 catch (Exception exception) 1230 {} 1231 } 1232 catch (Throwable exception) 1233 { 1234 continue; 1235 } 1236 } 1237 1238 shortcut.execPostAction(); 1239 1240 try 1241 { 1242 if (execFiles != null) 1243 { 1244 FileExecutor executor = new FileExecutor(execFiles); 1245 1246 } 1255 } 1256 catch (NullPointerException nep) 1257 { 1258 nep.printStackTrace(); 1259 } 1260 catch (RuntimeException cannot) 1261 { 1262 cannot.printStackTrace(); 1263 } 1264 1265 1266 shortcut.cleanUp(); 1267 } 1268 1269 1270 1271 1283 1284 1285 1292 private boolean shortcutRequiredFor(Vector packs) 1293 { 1294 String selected; 1295 String required; 1296 1297 if (packs.size() == 0) { return (true); } 1298 1299 for (int i = 0; i < idata.selectedPacks.size(); i++) 1300 { 1301 selected = ((Pack) idata.selectedPacks.get(i)).name; 1302 1303 for (int k = 0; k < packs.size(); k++) 1304 { 1305 required = (String ) ((XMLElement) packs.elementAt(k)).getAttribute( 1306 SPEC_ATTRIBUTE_NAME, ""); 1307 1308 if (selected.equals(required)) { return (true); } 1309 } 1310 } 1311 1312 return (false); 1313 } 1314 1315 1316 1317 1325 1326 1327 private String fixSeparatorChar(String path) 1328 { 1329 String newPath = path.replace('/', File.separatorChar); 1330 newPath = newPath.replace('\\', File.separatorChar); 1331 1332 return (newPath); 1333 } 1334 1335 1336 1337 1343 1344 1345 private void buildUI(File groups) 1346 { 1347 constraints.insets = new Insets(10, 10, 0, 0); 1348 1349 String menuKind = parent.langpack.getString("ShortcutPanel.regular.StartMenu:Start-Menu"); 1351 1352 if (OsVersion.IS_UNIX && UnixHelper.kdeIsInstalled()) 1353 { 1354 menuKind = parent.langpack.getString("ShortcutPanel.regular.StartMenu:K-Menu"); 1355 } 1356 1357 createShortcuts = new JCheckBox(StringTool.replace(parent.langpack 1358 .getString("ShortcutPanel.regular.create"), "StartMenu", menuKind), true); 1359 createShortcuts.addActionListener(this); 1360 constraints.gridx = col; 1361 constraints.gridy = line + 1; 1362 constraints.gridwidth = 1; 1363 constraints.gridheight = 1; 1364 1365 constraints.fill = GridBagConstraints.HORIZONTAL; 1368 constraints.anchor = GridBagConstraints.NORTHWEST; 1369 1370 layout.addLayoutComponent(createShortcuts, constraints); 1371 add(createShortcuts); 1372 1373 constraints.insets = new Insets(0, 10, 0, 0); 1374 1375 if (hasDesktopShortcuts) 1382 { 1383 String initialAllowedValue = idata.getVariable("DesktopShortcutCheckboxEnabled"); 1384 boolean initialAllowedFlag = false; 1385 1386 if (initialAllowedValue == null) 1387 { 1388 initialAllowedFlag = false; 1389 } 1390 else if (Boolean.TRUE.toString().equals(initialAllowedValue)) 1391 { 1392 initialAllowedFlag = true; 1393 } 1394 1395 allowDesktopShortcut = new JCheckBox(parent.langpack 1396 .getString("ShortcutPanel.regular.desktop"), initialAllowedFlag); 1397 constraints.gridx = col; 1398 constraints.gridy = line + 2; 1399 constraints.gridwidth = 1; 1400 constraints.gridheight = 1; 1401 1402 layout.addLayoutComponent(allowDesktopShortcut, constraints); 1406 add(allowDesktopShortcut); 1407 } 1408 1409 listLabel = LabelFactory.create(parent.langpack.getString("ShortcutPanel.regular.list"), 1410 JLabel.LEADING); 1411 1412 constraints.gridx = col; 1413 constraints.gridy = line + 3; 1414 constraints.gridwidth = 1; 1415 constraints.gridheight = 1; 1416 1417 constraints.insets = new Insets(10, 10, 0, 0); 1418 1419 constraints.fill = GridBagConstraints.HORIZONTAL; 1420 constraints.anchor = GridBagConstraints.NORTHWEST; 1421 1422 layout.addLayoutComponent(listLabel, constraints); 1423 add(listLabel); 1424 1425 Vector dirEntries = new Vector (); 1430 1431 File[] entries = groups.listFiles(); 1432 1433 if (entries != null) 1436 { 1437 for (int idx = 0; idx < entries.length; idx++) 1438 { 1439 if (entries[idx].isDirectory()) 1440 { 1441 dirEntries.add(entries[idx].getName()); 1442 } 1443 } 1444 } 1445 1446 if (groupList == null) 1447 { 1448 groupList = new JList(); 1449 } 1450 1451 groupList = addList(dirEntries, ListSelectionModel.SINGLE_SELECTION, groupList, col, 1452 line + 4, 1, 1, GridBagConstraints.BOTH); 1453 1454 if (shortcut.multipleUsers()) 1458 { 1459 JPanel usersPanel = new JPanel(new GridLayout(2, 1)); 1460 ButtonGroup usersGroup = new ButtonGroup(); 1461 currentUser = new JRadioButton(parent.langpack 1462 .getString("ShortcutPanel.regular.currentUser"), !isRootUser); 1463 currentUser.addActionListener(this); 1464 usersGroup.add(currentUser); 1465 usersPanel.add(currentUser); 1466 allUsers = new JRadioButton( 1467 parent.langpack.getString("ShortcutPanel.regular.allUsers"), isRootUser); 1468 1469 Debug.log("allUsers.setEnabled(), I'm Root: " + isRootUser); 1470 1471 allUsers.setEnabled(isRootUser); 1472 1473 allUsers.addActionListener(this); 1474 usersGroup.add(allUsers); 1475 usersPanel.add(allUsers); 1476 1477 TitledBorder border = new TitledBorder (new EmptyBorder (2, 2, 2, 2), parent.langpack 1478 .getString("ShortcutPanel.regular.userIntro")); 1479 usersPanel.setBorder(border); 1480 1481 constraints.gridx = col + 1; 1482 constraints.gridy = line + 4; 1483 constraints.gridwidth = 1; 1484 constraints.gridheight = 1; 1485 1486 constraints.fill = GridBagConstraints.HORIZONTAL; 1489 layout.addLayoutComponent(usersPanel, constraints); 1490 add(usersPanel); 1491 } 1492 1493 programGroup = new JTextField(suggestedProgramGroup, 40); 1500 constraints.gridx = col; 1501 constraints.gridy = line + 5; 1502 constraints.gridwidth = 1; 1503 constraints.gridheight = 1; 1504 1505 constraints.fill = GridBagConstraints.HORIZONTAL; 1508 layout.addLayoutComponent(programGroup, constraints); 1509 add(programGroup); 1510 1511 defaultButton = ButtonFactory.createButton(parent.langpack 1516 .getString("ShortcutPanel.regular.default"), idata.buttonsHColor); 1517 defaultButton.addActionListener(this); 1518 1519 constraints.gridx = col + 1; 1520 constraints.gridy = line + 5; 1521 constraints.gridwidth = 1; 1522 constraints.gridheight = 1; 1523 constraints.fill = GridBagConstraints.HORIZONTAL; 1524 layout.addLayoutComponent(defaultButton, constraints); 1525 add(defaultButton); 1526 } 1527 1528 1542 private JList addList(Vector Entries, int ListModel, JList aJList, int aGridx, int aGridy, 1543 int aGridwidth, int aGridheight, int aFill) 1544 { 1545 if (aJList == null) 1546 { 1547 aJList = new JList(Entries); 1548 } 1549 else 1550 { 1551 aJList.setListData(Entries); 1552 } 1553 1554 aJList.setSelectionMode(ListModel); 1555 aJList.getSelectionModel().addListSelectionListener(this); 1556 1557 JScrollPane scrollPane = new JScrollPane(aJList); 1558 1559 constraints.gridx = aGridx; 1560 constraints.gridy = aGridy; 1561 constraints.gridwidth = aGridwidth; 1562 constraints.gridheight = aGridheight; 1563 constraints.weightx = 2.0; 1564 constraints.weighty = 1.5; 1565 constraints.insets = new Insets(5, 5, 5, 5); 1566 constraints.fill = aFill; 1567 layout.addLayoutComponent(scrollPane, constraints); 1568 add(scrollPane); 1569 1570 return aJList; 1571 } 1572 1573 1581 1582 1583 private void buildAlternateUI() 1584 { 1585 layout = new GridBagLayout(); 1586 constraints = new GridBagConstraints(); 1587 setLayout(layout); 1588 1589 MultiLineLabel apologyLabel = new MultiLineLabel(parent.langpack 1595 .getString("ShortcutPanel.alternate.apology"), 0, 0); 1596 1597 constraints.gridx = 0; 1598 constraints.gridy = 0; 1599 constraints.gridwidth = 1; 1600 constraints.gridheight = 1; 1601 constraints.weightx = 1.0; 1602 constraints.weighty = 1.0; 1603 constraints.insets = new Insets(5, 5, 5, 5); 1604 constraints.fill = GridBagConstraints.HORIZONTAL; 1605 constraints.anchor = GridBagConstraints.WEST; 1606 layout.addLayoutComponent(apologyLabel, constraints); 1607 add(apologyLabel); 1608 1609 MultiLineLabel listLabel = new MultiLineLabel(parent.langpack 1613 .getString("ShortcutPanel.alternate.targetsLabel"), 0, 0); 1614 1615 constraints.gridx = 0; 1616 constraints.gridy = 1; 1617 constraints.gridwidth = 1; 1618 constraints.gridheight = 1; 1619 constraints.weightx = 1.0; 1620 constraints.weighty = 1.0; 1621 layout.addLayoutComponent(listLabel, constraints); 1622 add(listLabel); 1623 1624 Vector targets = new Vector (); 1628 1629 for (int i = 0; i < shortcuts.size(); i++) 1630 { 1631 targets.add(((ShortcutData) shortcuts.elementAt(i)).target); 1632 } 1633 1634 targetList = new JList(targets); 1635 1636 JScrollPane scrollPane = new JScrollPane(targetList); 1637 1638 constraints.gridx = 0; 1639 constraints.gridy = 2; 1640 constraints.fill = GridBagConstraints.BOTH; 1641 layout.addLayoutComponent(scrollPane, constraints); 1642 add(scrollPane); 1643 1644 MultiLineLabel fileExplanation = new MultiLineLabel(parent.langpack 1648 .getString("ShortcutPanel.alternate.textFileExplanation"), 0, 0); 1649 1650 constraints.gridx = 0; 1651 constraints.gridy = 3; 1652 constraints.weightx = 1.0; 1653 constraints.weighty = 1.0; 1654 constraints.fill = GridBagConstraints.HORIZONTAL; 1655 layout.addLayoutComponent(fileExplanation, constraints); 1656 add(fileExplanation); 1657 1658 saveButton = ButtonFactory.createButton(parent.langpack 1662 .getString("ShortcutPanel.alternate.saveButton"), idata.buttonsHColor); 1663 saveButton.addActionListener(this); 1664 1665 constraints.gridx = 0; 1666 constraints.gridy = 4; 1667 constraints.gridwidth = 1; 1668 constraints.gridheight = 1; 1669 constraints.fill = GridBagConstraints.NONE; 1670 constraints.anchor = GridBagConstraints.CENTER; 1671 layout.addLayoutComponent(saveButton, constraints); 1672 add(saveButton); 1673 } 1674 1675 1676 1677 1682 1683 1684 public Dimension getSize() 1685 { 1686 Dimension size = getParent().getSize(); 1687 Insets insets = getInsets(); 1688 Border border = getBorder(); 1689 Insets borderInsets = new Insets(0, 0, 0, 0); 1690 1691 if (border != null) 1692 { 1693 borderInsets = border.getBorderInsets(this); 1694 } 1695 1696 size.height = size.height - insets.top - insets.bottom - borderInsets.top 1697 - borderInsets.bottom - 50; 1698 size.width = size.width - insets.left - insets.right - borderInsets.left 1699 - borderInsets.right - 50; 1700 1701 return (size); 1702 } 1703 1704 1705 1706 1709 1710 1711 private void saveToFile() 1712 { 1713 File file = null; 1714 1715 JFileChooser fileDialog = new JFileChooser(idata.getInstallPath()); 1719 fileDialog.setSelectedFile(new File(TEXT_FILE_NAME)); 1720 1721 if (fileDialog.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) 1722 { 1723 file = fileDialog.getSelectedFile(); 1724 } 1725 else 1726 { 1727 return; 1728 } 1729 1730 FileWriter output = null; 1734 StringBuffer buffer = new StringBuffer (); 1735 String header = parent.langpack.getString("ShortcutPanel.textFile.header"); 1736 1737 String newline = System.getProperty("line.separator", "\n"); 1738 1739 try 1740 { 1741 output = new FileWriter (file); 1742 } 1743 catch (Throwable exception) 1744 { 1745 return; 1747 } 1748 1749 int nextIndex = 0; 1754 int currentIndex = 0; 1755 1756 do 1757 { 1758 nextIndex = header.indexOf("\\n", currentIndex); 1759 1760 if (nextIndex > -1) 1761 { 1762 buffer.append(header.substring(currentIndex, nextIndex)); 1763 buffer.append(newline); 1764 currentIndex = nextIndex + 2; 1765 } 1766 else 1767 { 1768 buffer.append(header.substring(currentIndex, header.length())); 1769 buffer.append(newline); 1770 } 1771 } 1772 while (nextIndex > -1); 1773 1774 buffer.append(SEPARATOR_LINE); 1775 buffer.append(newline); 1776 buffer.append(newline); 1777 1778 for (int i = 0; i < shortcuts.size(); i++) 1779 { 1780 ShortcutData data = (ShortcutData) shortcuts.elementAt(i); 1781 1782 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.name")); 1783 buffer.append(data.name); 1784 buffer.append(newline); 1785 1786 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.location")); 1787 1788 switch (data.type) 1789 { 1790 case Shortcut.DESKTOP: { 1791 buffer.append(parent.langpack.getString("ShortcutPanel.location.desktop")); 1792 1793 break; 1794 } 1795 1796 case Shortcut.APPLICATIONS: { 1797 buffer.append(parent.langpack.getString("ShortcutPanel.location.applications")); 1798 1799 break; 1800 } 1801 1802 case Shortcut.START_MENU: { 1803 buffer.append(parent.langpack.getString("ShortcutPanel.location.startMenu")); 1804 1805 break; 1806 } 1807 1808 case Shortcut.START_UP: { 1809 buffer.append(parent.langpack.getString("ShortcutPanel.location.startup")); 1810 1811 break; 1812 } 1813 } 1814 1815 buffer.append(newline); 1816 1817 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.description")); 1818 buffer.append(data.description); 1819 buffer.append(newline); 1820 1821 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.target")); 1822 buffer.append(data.target); 1823 buffer.append(newline); 1824 1825 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.command")); 1826 buffer.append(data.commandLine); 1827 buffer.append(newline); 1828 1829 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.iconName")); 1830 buffer.append(data.iconFile); 1831 buffer.append(newline); 1832 1833 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.iconIndex")); 1834 buffer.append(data.iconIndex); 1835 buffer.append(newline); 1836 1837 buffer.append(parent.langpack.getString("ShortcutPanel.textFile.work")); 1838 buffer.append(data.workingDirectory); 1839 buffer.append(newline); 1840 1841 buffer.append(newline); 1842 buffer.append(SEPARATOR_LINE); 1843 buffer.append(newline); 1844 buffer.append(newline); 1845 } 1846 1847 try 1848 { 1849 output.write(buffer.toString()); 1850 } 1851 catch (Throwable exception) 1852 {} 1853 finally 1854 { 1855 try 1856 { 1857 output.flush(); 1858 output.close(); 1859 files.add(file.getPath()); 1860 } 1861 catch (Throwable exception) 1862 { 1863 } 1866 } 1867 } 1868 1869 1870 1871 1874 1875 1876 private void addToUninstaller() 1877 { 1878 UninstallData uninstallData = UninstallData.getInstance(); 1879 1880 for (int i = 0; i < files.size(); i++) 1881 { 1882 uninstallData.addFile((String ) files.elementAt(i)); 1883 } 1884 } 1885 1886 1887 1888 1891 public static ShortcutPanel getInstance( ) 1892 { 1893 return self; 1894 } 1895 1896 1897 1905 public void makeXMLData( XMLElement panelRoot ) 1906 { 1907 Debug.log( "entering makeXMLData" ); 1914 1915 1916 if (!shortcutsToCreate || !shortcut.supported() || (groupName == null) 1917 || simulteNotSupported || ! create ) { Debug.log( "abort makeXMLData!" ); return; } 1918 1919 ShortcutData data; 1920 XMLElement dataElement; 1921 1922 dataElement = new XMLElement(AUTO_KEY_PROGRAM_GROUP); 1926 dataElement.setAttribute(AUTO_ATTRIBUTE_NAME, groupName); 1927 panelRoot.addChild(dataElement); 1928 1929 for (int i = 0; i < shortcuts.size(); i++) 1933 { 1934 Debug.log( "entering makeXMLData" ); 1935 data = (ShortcutData) shortcuts.elementAt(i); 1936 dataElement = new XMLElement(AUTO_KEY_SHORTCUT); 1937 1938 dataElement.setAttribute(AUTO_ATTRIBUTE_NAME, data.name); 1939 dataElement.setAttribute(AUTO_ATTRIBUTE_GROUP, (data.addToGroup ? Boolean.TRUE 1940 : Boolean.FALSE).toString()); 1941 1942 if(OsVersion.IS_WINDOWS) 1944 1945 dataElement.setAttribute(AUTO_ATTRIBUTE_TYPE, Integer.toString(data.type)); 1946 dataElement.setAttribute(AUTO_ATTRIBUTE_COMMAND, data.commandLine); 1947 dataElement.setAttribute(AUTO_ATTRIBUTE_DESCRIPTION, data.description); 1948 dataElement.setAttribute(AUTO_ATTRIBUTE_ICON, data.iconFile); 1949 dataElement.setAttribute(AUTO_ATTRIBUTE_ICON_INDEX, Integer.toString(data.iconIndex)); 1950 dataElement.setAttribute(AUTO_ATTRIBUTE_INITIAL_STATE, Integer 1951 .toString(data.initialState)); 1952 dataElement.setAttribute(AUTO_ATTRIBUTE_TARGET, data.target); 1953 dataElement.setAttribute(AUTO_ATTRIBUTE_WORKING_DIR, data.workingDirectory); 1954 1955 1956 dataElement.setAttribute( SPEC_ATTRIBUTE_ENCODING, data.deskTopEntryLinux_Encoding ); 1957 dataElement.setAttribute( SPEC_ATTRIBUTE_MIMETYPE, data.deskTopEntryLinux_MimeType ); 1958 dataElement.setAttribute( SPEC_ATTRIBUTE_TERMINAL, data.deskTopEntryLinux_Terminal ); 1959 dataElement.setAttribute( SPEC_ATTRIBUTE_TERMINAL_OPTIONS, data.deskTopEntryLinux_TerminalOptions ); 1960 if(! OsVersion.IS_WINDOWS ) 1961 dataElement.setAttribute( SPEC_ATTRIBUTE_TYPE, data.deskTopEntryLinux_Type ); 1962 1963 dataElement.setAttribute( SPEC_ATTRIBUTE_URL, data.deskTopEntryLinux_URL ); 1964 1965 dataElement.setAttribute( SPEC_ATTRIBUTE_KDE_SUBST_UID, data.deskTopEntryLinux_X_KDE_SubstituteUID ); 1966 dataElement.setAttribute( SPEC_CATEGORIES, data.Categories ); 1967 dataElement.setAttribute( SPEC_TRYEXEC, data.TryExec ); 1968 1969 dataElement.setAttribute( CREATE_FOR_ALL, data.createForAll.toString() ); dataElement.setAttribute( USER_TYPE, Integer.toString( data.userType ) ); 1971 1972 1973 1974 1976 if ((data.type != Shortcut.DESKTOP) 1983 || ((data.type == Shortcut.DESKTOP) && allowDesktopShortcut.isSelected())) 1984 { 1985 panelRoot.addChild(dataElement); 1986 } 1987 } 1988 } 1989 1990 1991 1992 1997 1998 1999 2008 2009 2010} 2011 2012 2013 | Popular Tags |