home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / edispm11.zip / EDisPM / SRC / Client / EDADM.CPP next >
Text File  |  1996-05-12  |  13KB  |  423 lines

  1. /* EDAdm.cpp: EDDocAdmin:       EDisPM.EXE V 1.1 */
  2. /* Editorclient - Text Server Verwaltung         */
  3. /*                                               */
  4. /* (C) 1995 M.Schwarz, FoPra TU-Muenchen SS1995  */
  5. /* (C) 1996 M.Schwarz, SOMObjects-Programmierung */
  6. /*                     OS/2 Inside 7/96          */
  7. /*                                               */
  8. /* latest changes: 11.5.1996                     */
  9. /*-----------------------------------------------*/
  10.  
  11. #include "EDADM.HPP"
  12.  
  13. #include <ifiledlg.hpp>
  14. #include <fstream.h>
  15. #include <imsgbox.hpp>
  16. #include <icnrcol.hpp>
  17. #include <icnrobj.hpp>
  18. #include <icnrhdr.hpp>
  19. #include <ipushbut.hpp>
  20. #include <isetcv.hpp>
  21. #include <ipushbut.hpp>
  22. #include <isetcv.hpp>
  23.  
  24. #define MARGIN 10
  25. #define IDD_DOCNEW 14001
  26. #define IDD_DOCDEL 14002
  27.  
  28. void weiter(IString text)
  29. {
  30.    IMessageBox imb(IWindow::objectWindow());
  31.    imb.setTitle("Profilebearbeitung-Info");
  32.    imb.show(text, IMessageBox::okButton);
  33. }
  34.  
  35. /* Implementierung der Klasse EDDocAdmin */
  36.  
  37. EDDocAdmin::EDDocAdmin (IWindow* p)
  38. {
  39.   /* Parent/Owner-Window speichern */
  40.    parent = p;
  41.    EDProfile = (IProfile *) 0;
  42. }
  43.  
  44.  
  45. EDDocAdmin::~EDDocAdmin()
  46. {
  47.   /* Profile (INI-Datei) schließen */
  48.    if (EDProfile) {
  49.       delete EDProfile;
  50.    } /* endif */
  51. }
  52.  
  53.  
  54. short EDDocAdmin::openProfile()
  55. {
  56.    short rc = 1;
  57.  
  58.   /* Hole INI-Pfad aus der OS/2-UserIni */
  59.    try {
  60.       profPath = IProfile::userProfile().elementWithKey("Profile-Pfad", "EDisPM");
  61.    } /* end try */
  62.  
  63.   /* Fehlerbehandlung -> Pfad nicht in OS/2 Userprofile */
  64.    catch ( const IAccessError &exception ) {
  65.       IFileDialog::Settings dlgSettings;
  66.       dlgSettings.setTitle("Textzuordnugsdatei festlegen");
  67.       dlgSettings.setFileName("EDisPM.INI");
  68.       IFileDialog dlg(0, parent, IFileDialog::defaultStyle(), dlgSettings);
  69.       if (dlg.pressedOK()) {
  70.         /* Profile-Pfad einlesen */
  71.          profPath = dlg.fileName();
  72.         /* Speichere Profile-Pfad in der OS/2-Ini */
  73.          IProfile::userProfile().addOrReplaceElementWithKey("Profile-Pfad", profPath, "EDisPM");
  74.       } else {
  75.          rc = 0;
  76.       } /* endif */
  77.    } /* end catch */
  78.  
  79.   /* Profile öffnen */
  80.    try {
  81.       if (rc) {
  82.          EDProfile = new IProfile(profPath);
  83.       } /* endif */
  84.    } /* end try */
  85.  
  86.   /* Fehlerbehandlung -> Profile öffnen */
  87.    catch ( const IString &msg ) {
  88.      /* Display Error Message */
  89.       IMessageBox msgBox(IWindow::objectWindow());
  90.       msgBox.show(msg, msgBox.cancelButton);
  91.       IProfile::userProfile().deleteElementWithKey("Profile-Pfad", "EDisPM");
  92.       rc = 0;
  93.    } /* end catch */
  94.  
  95.   /* Erfolgreich zurück */
  96.    return rc;
  97. }
  98.  
  99. /*
  100. IString EDDocAdmin::validate ( const IString &name )
  101. {
  102.    int      option = 0;
  103.    IString  outName( name );
  104.    ifstream test( outName, option );
  105.  
  106.    if ( !test ) {
  107.       outName += ".ini";
  108.       ifstream test( outName, option );
  109.       if ( !test ) {
  110.          IString msg( "Profile-Datei kann nicht geöffnet werden " );
  111.          msg += outName;
  112.          throw msg;
  113.       }
  114.    }
  115.    return outName;
  116. }
  117. */
  118.  
  119. short EDDocAdmin::getDocFromID(IString *DocID, IString *DocPath, IString *DocServer) {
  120.    short rc = 0;
  121.  
  122.    if (*DocID != "") {
  123.       try {
  124.          *DocPath   = EDProfile->elementWithKey("FilePath", *DocID);
  125.          *DocServer = EDProfile->elementWithKey("DSomServer", *DocID);
  126.          rc = 1;
  127.       } /* end try */
  128.       catch ( const IAccessError &exception  ) {
  129.          weiter("Der Texteintrag "+*DocID+" kann nicht geöffnet werden.");
  130.       } /* end catch */
  131.    } /* endif */
  132.    if ((*DocPath == "") || (*DocServer == "") ) {
  133.       rc = 0;
  134.    } /* endif */
  135.  
  136.    return rc;
  137. }
  138.  
  139. short EDDocAdmin::chooseDoc(IString *DocID, IString *DocPath, IString *DocServer) {
  140.    short rc = 0;
  141.  
  142.    EDDocOpenDlg dlg(DocID, parent, EDProfile);
  143.    if (*DocID != "") {
  144.       try {
  145.          *DocPath   = EDProfile->elementWithKey("FilePath", *DocID);
  146.          *DocServer = EDProfile->elementWithKey("DSomServer", *DocID);
  147.          rc = 1;
  148.       } /* end try */
  149.       catch ( const IAccessError &exception  ) {
  150.          weiter("Der Texteintrag "+*DocID+" kann nicht geöffnet werden.");
  151.          rc = 0;
  152.       } /* end catch */
  153.    } /* endif */
  154.    return rc;
  155. }
  156.  
  157.  
  158.  
  159. short EDDocAdmin::setServer(IString *DocID, IString *DocServer) {
  160.    short rc = 0;
  161.    if (*DocID != "") {
  162.       try {
  163.          EDProfile->addOrReplaceElementWithKey("DSomServer", *DocServer, *DocID);
  164.          rc = 1;
  165.       } /* end try */
  166.       catch ( const IAccessError &exception  ) {
  167.          weiter("Der Servereintrag zu "+*DocID+" kann nicht gesetzt werden.");
  168.          rc = 0;
  169.       } /* end catch */
  170.    } /* endif */
  171.    return rc;
  172. }
  173.  
  174.  
  175.  
  176. /* Implementierung der Containerobjekt-Klasse */
  177.  
  178. class DocCnrObj : public IContainerObject {
  179.    public:
  180.       DocCnrObj( IString name, IProfile profile) :
  181.          IContainerObject(name, 0)
  182.       {
  183.          strFilePath   = profile.elementWithKey("FilePath", name);
  184.          strDSomServer = profile.elementWithKey("DSomServer", name);
  185.          if (strDSomServer == "NO") {
  186.             strStatus = "-----";
  187.          } else {
  188.             strStatus = "läuft";
  189.          } /* endif */
  190.       }
  191.  
  192.       static unsigned long statusOffset() {
  193.          return offsetof(DocCnrObj, strStatus);
  194.       }
  195.  
  196.       static unsigned long filepathOffset() {
  197.          return offsetof(DocCnrObj, strFilePath);
  198.       }
  199.  
  200.       static unsigned long dsomserverOffset() {
  201.          return offsetof(DocCnrObj, strDSomServer);
  202.       }
  203.  
  204.    private:
  205.       IString strFilePath;
  206.       IString strStatus;
  207.       IString strDSomServer;
  208. };
  209.  
  210.  
  211. /* Implementierung der Text-Öffnen-Neu-Fenster-Klasse */
  212.  
  213. Boolean EDDocNewDlg::command (ICommandEvent& event)
  214. {
  215.    Boolean dontPassOn = false;
  216.    switch (event.commandId()) {
  217.    case IDD_NEUFILE: {
  218.          IFileDialog dlg(0, event.window(), IFileDialog::defaultStyle(), IFileDialog::Settings());
  219.          if (dlg.pressedOK()) {
  220.             entryFilePath.setText(dlg.fileName());
  221.          } /* endif */
  222.       }
  223.       break;
  224.    case DID_OK:
  225.       *docName = entryName.text();
  226.       *docFilePath = entryFilePath.text();
  227.       if (((*docName).length() > 0) && ((*docFilePath).length() > 0)) {
  228.          ((IFrameWindow*) (event.window()))->dismiss(event.commandId());
  229.       } /* endif */
  230.       dontPassOn = true;
  231.       break;
  232.    case DID_CANCEL:
  233.       *docName = "";
  234.       ((IFrameWindow*) (event.window()))->dismiss(event.commandId());
  235.       dontPassOn = true;
  236.       break;
  237.    } /* endswitch */
  238.    return dontPassOn;
  239. }
  240.  
  241.  
  242. EDDocNewDlg::EDDocNewDlg(IFrameWindow* parent, IString *dN, IString *dFP) :
  243.    IFrameWindow(IDD_OPENNEW, parent),
  244.    entryName(IDD_NDOCID, this),
  245.    entryFilePath(IDD_NDOCFILENAME, this)
  246. {
  247.    docName = dN;
  248.    docFilePath = dFP;
  249.  
  250.    IFrameHandler::handleEventsFor(this);
  251.    setFocus();
  252.    entryName.setFocus();
  253.    entryFilePath.setLimit(255);
  254.    showModally();
  255. }
  256.  
  257.  
  258.  
  259. /* Implementierung der Editor-Open-Dialog-Klasse */
  260.  
  261. Boolean EDDocOpenDlg::command (ICommandEvent& event)
  262. {
  263.    Boolean dontPassOn = false;
  264.    switch (event.commandId()) {
  265.    case IDD_DOCNEW: {
  266.          IString strName("");
  267.          IString strFilePath("");
  268.          EDDocNewDlg dlg(this, &strName, &strFilePath);
  269.  
  270.          if (strName != "") {
  271.            /* Neuer Eintrag in Profile schreiben */
  272.             try {
  273.                profile->addOrReplaceElementWithKey("DSomServer", "NO", strName);
  274.                profile->addOrReplaceElementWithKey("FilePath", strFilePath, strName);
  275.               /* Neuer Eintrag in den Container eintragen */
  276.                DocCnrObj *docObj = new DocCnrObj(strName, *profile);
  277.                DocOpenCnr.addObject(docObj)
  278.                          .sortByIconText();
  279.             } /* end try */
  280.             catch ( const IAccessError &exception  ) {
  281.                weiter("Der Eintrag "+strName+" konnte nicht hinzugefügt werden.");
  282.             } /* end catch */
  283.          } /* endif */
  284.       }
  285.       break;
  286.    case IDD_DOCDEL: {
  287.          DocCnrObj *docObj = (DocCnrObj *) DocOpenCnr.cursoredObject();
  288.          IString strName = docObj->iconText();
  289.  
  290.          if (strName!="") {
  291.             try {
  292.                if (profile->elementWithKey("DSomServer",strName) != "NO") {
  293.                  /* Server läuft gerade, trotzdem löschen ? */
  294.                   IMessageBox imb(IWindow::objectWindow());
  295.                   imb.setTitle("Profilebearbeitung-Info");
  296.                   if (IMessageBox::ok != imb.show("Der Text wird noch von einem Server bearbeitet, Eintrag trotzdem löschen? ", IMessageBox::okCancelButton))
  297.                      break;
  298.                } /* endif */
  299.               /* Server-Eintrag löschen */
  300.                profile->deleteElementWithApplication(strName);
  301.                DocOpenCnr.removeObject(docObj)
  302.                          .sortByIconText();
  303.             } /* end try */
  304.             catch ( const IAccessError &exception  ) {
  305.                weiter("Der Texteintag "+strName+" konnte nicht gelöscht werden.");
  306.             } /* end catch */
  307.          } /* endif */
  308.       }
  309.       break;
  310.    case DID_OK: {
  311.          DocCnrObj *docObj = (DocCnrObj *) DocOpenCnr.cursoredObject();
  312.          *docName =  docObj->iconText();
  313.          ((IFrameWindow*) (event.window()))->dismiss(event.commandId());
  314.          dontPassOn = true;
  315.       }
  316.       break;
  317.    case DID_CANCEL:
  318.       ((IFrameWindow*) (event.window()))->dismiss(event.commandId());
  319.       dontPassOn = true;
  320.       break;
  321.    } /* endswitch */
  322.    return dontPassOn;
  323. }
  324.  
  325.  
  326. EDDocOpenDlg::EDDocOpenDlg(IString* dN, IWindow* parent, IProfile *p) :
  327.    IFrameWindow( 0,0,parent, IFrameWindow::nextShellRect().scaleBy(0.6, 0.5),
  328.                   IFrameWindow::classDefaultStyle
  329.                 & ~IFrameWindow::maximizeButton
  330.                 & ~IFrameWindow::minimizeButton
  331.                 | IFrameWindow::dialogBackground, "Öffnen"),
  332.    DocOpenClient(0, this, this),
  333.    DocOpenCnr   (0, &DocOpenClient, &DocOpenClient)
  334. {
  335.    profile = p;
  336.    docName = dN;
  337.    *docName = "";
  338.  
  339.   /* Erstelle Dateiauswahl-Container */
  340.    IContainerColumn* pcolumn;
  341.  
  342.    pcolumn = new IContainerColumn(IContainerColumn::isIconViewText);
  343.    pcolumn->setHeadingText("Name");
  344.    pcolumn->showSeparators(IContainerColumn::horizontalSeparator);
  345.    DocOpenCnr.addColumn(pcolumn);
  346.    DocOpenCnr.setDetailsViewSplit(pcolumn, 100);
  347.  
  348.    pcolumn = new IContainerColumn(DocCnrObj::statusOffset());
  349.    pcolumn->setHeadingText("Status");
  350.    pcolumn->showSeparators();
  351.    DocOpenCnr.addColumn(pcolumn);
  352.  
  353.    pcolumn = new IContainerColumn(DocCnrObj::filepathOffset());
  354.    pcolumn->setHeadingText("Dateipfad");
  355.    pcolumn->showSeparators(IContainerColumn::horizontalSeparator);
  356.    DocOpenCnr.addColumn(pcolumn);
  357.  
  358.    DocOpenCnr
  359.       .setSingleSelection()
  360.       .setDeleteColumnsOnClose()
  361.       .setDeleteObjectsOnClose()
  362.       .showSplitBar()
  363.       .showTitleSeparator()
  364.       .showDetailsView()
  365.       .enableTabStop();
  366.  
  367.   /* Erstelle Buttons */
  368.    ISetCanvas  BSpace(0x800C, &DocOpenClient, &DocOpenClient);
  369.    IPushButton BOk(DID_OK, &BSpace, &BSpace);
  370.    IPushButton BCancel(DID_CANCEL, &BSpace, &BSpace);
  371.    IPushButton BNew(IDD_DOCNEW, &BSpace, &BSpace);
  372.    IPushButton BDelete(IDD_DOCDEL, &BSpace, &BSpace);
  373.    BOk.enableDefault()
  374.       .setText( "~OK" )
  375.       .enableTabStop()
  376.       .enableGroup();
  377.    BCancel
  378.       .setText( "A~bbruch" )
  379.       .enableTabStop();
  380.    BNew
  381.       .setText("~Neu")
  382.       .enableTabStop();
  383.    BDelete
  384.       .setText("~Löschen")
  385.       .enableTabStop();
  386.    BSpace
  387.      .setMargin( ISize() )
  388.      .setPackType( ISetCanvas::expanded );
  389.  
  390.   /* Baue Fenster auf */
  391.    ISize defaultCell = IMultiCellCanvas::defaultCell();
  392.    DocOpenClient
  393.       .addToCell(&DocOpenCnr,  2, 2, 3)
  394.       .addToCell(&BSpace,      2, 4);
  395.  
  396.    DocOpenClient
  397.       .setColumnWidth(1, MARGIN)
  398.       .setColumnWidth(4, MARGIN)
  399.       .setColumnWidth(3, defaultCell.width(), true)
  400.       .setRowHeight  (1, MARGIN)
  401.       .setRowHeight  (2, defaultCell.height(), true)
  402.       .setRowHeight  (3, MARGIN)
  403.       .setRowHeight  (5, MARGIN);
  404.  
  405.   /* Text-Einträge aus Profile einlesen */
  406.   /* Profile-Cursor, um Text-Einträge auszulesen */
  407.    IProfile::Cursor cursor(*profile);
  408.    for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext() ) {
  409.       IString   strDocName = profile->applicationOrKeyAt(cursor);
  410.       DocCnrObj *docObj = new DocCnrObj(strDocName, *profile);
  411.       DocOpenCnr.addObject(docObj);
  412.    } /* endfor */
  413.  
  414.    DocOpenCnr.sortByIconText();
  415.  
  416.   /* Fenster anzeigen und abfragen */
  417.    IFrameHandler::handleEventsFor(this);
  418.    setClient(&DocOpenClient);
  419.    setFocus();
  420.    showModally();
  421. }
  422.  
  423.