SOL9 2.0 Class: FilePropertyViewer

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * FilePropertyViewer.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/09/16


#include <sol\PopupView.h>
#include <sol\ListView.h>
#include <sol\PushButton.h>
#include <sol/StringConverter.h>
#include <sol\MessageFont.h>
#include <sol\FileAttributes.h>

namespace SOL {

class FilePropertyViewer: public PopupView {

private:
//    FileProperty    version;
    ListView    listview;
    PushButton    ok;
    MessageFont mfont;
    bool columns;

public:
    FilePropertyViewer()
        :PopupView()
    {
    }

public:
    FilePropertyViewer(View* parent, const TCHAR* label, Args& args)
    :PopupView(parent, label,        
            args.set(XmNwidth, 540)
                .set(XmNheight, 300)
                .set(XmNstyle, WS_SIZEBOX|WS_THICKFRAME))
    {
    
        Args ar;
//        ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
        ar.set(XmNstyle, (ulong)LVS_REPORT);
        listview.create(this, "", ar);
//        const TCHAR* labels[] = {"Name", "Value"};
//        listview.setColumn(labels, 2);
        ListViewColumn columns[] = {
            {_T("Name"),  LVCFMT_LEFT, 140},
            {_T("Value"), LVCFMT_LEFT, 380},
        };

        listview.setColumn(columns, 2);

        
        ar.reset();
        ok.create(this, _T("OK"), ar);
        mfont.create();
    
        ok.setFont(mfont.getFont());
        ok.addCallback(XmNactivateCallback, this,
                    (Callback)&FilePropertyViewer::popdown, NULL);
        resize();

        const TCHAR* fileName = (const TCHAR*)args.get(XmNfileName);
        
        showFileInfo(fileName);
        addEventHandler(WM_SIZE, this, 
            (Handler)&FilePropertyViewer::size, NULL);
    }

public:
    Boolean create(View* parent)
    {
        Boolean rc = False;
        Args args;
        args.set(XmNwidth, 540);
        args.set(XmNheight, 300);
        args.set(XmNstyle, WS_SIZEBOX|WS_THICKFRAME);

        rc = PopupView::create(parent, _T("FileProperty"), args);

        Args ar;
        //ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
        ar.set(XmNstyle, (ulong)LVS_REPORT);
        listview.create(this, "", ar);
        //const TCHAR* labels[] = {"Name", "Value"};
        //listview.setColumn(labels, 2);
        ListViewColumn columns[] = {
            {_T("Name"),  LVCFMT_LEFT, 140},
            {_T("Value"), LVCFMT_LEFT, 380},
        };

        listview.setColumn(columns, 2);

        ar.reset();
        ok.create(this, _T("OK"), ar);
        mfont.create();
    
        ok.setFont(mfont.getFont());
        ok.addCallback(XmNactivateCallback, this,
                    (Callback)&FilePropertyViewer::popdown, NULL);
        resize();
        const TCHAR* fileName = (const TCHAR*)args.get(XmNfileName);
        
        showFileInfo(fileName);
        addEventHandler(WM_SIZE, this, 
            (Handler)&FilePropertyViewer::size, NULL);

        return rc;                    
    }


private:
    void setWindowTitle(const TCHAR* title) {
        if (title) {
            if (strlen(title)>0) {
                TCHAR msg[1024];
                _stprintf_s(msg, SizeOf(msg), _T("%s - FileProperty"), title);
                setText(msg);
            }
        }
    }

public:
    bool showFileInfo(const TCHAR* fileName)
    {
        bool rc = false;

        listview.clear();
    
        if (fileName == NULL) {
            return rc;
        }

        try {
            int n=0;
            FileAttributes attrs(fileName);

            setWindowTitle(fileName);

            const TCHAR* text[2];
            text[0] = _T("Name");
            String fileName;
            attrs.getFileName(fileName);

            text[1] = (TCHAR*)(const TCHAR*)fileName;
            listview.insertLine(n++, text, 2);

            text[0] = _T("Size");
            String fileSize;
            attrs.getFileKBSize(fileSize);
            text[1] = (TCHAR*)(const TCHAR*)fileSize;
            listview.insertLine(n++, text, 2);

            text[0] = _T("CreationTime");
            String creationTime;
            attrs.getCreationTime(creationTime);
            text[1] = (TCHAR*)(const TCHAR*)creationTime;
            listview.insertLine(n++, text, 2);

            text[0] = _T("LastAccessTime");
            String lastAccessTime;
            attrs.getLastAccessTime(lastAccessTime);
            text[1] = (TCHAR*)(const TCHAR*)lastAccessTime;
            listview.insertLine(n++, text, 2);

            text[0] = _T("LastModifiedTime");
            String lastModifiedTime;
            attrs.getLastModifiedTime(lastModifiedTime);
            text[1] = (TCHAR*)(const TCHAR*)lastModifiedTime;
            listview.insertLine(n++, text, 2);

            text[0] = _T("Type");
            String type;
            attrs.getFileType(type);
            text[1] = (TCHAR*)(const TCHAR*)type;
            listview.insertLine(n++, text, 2);

            text[0] = _T("Attributes");
            String fileAttrs;
            attrs.getAttributes(fileAttrs);

            text[1] = (TCHAR*)(const TCHAR*)fileAttrs;
            listview.insertLine(n++, text, 2);

            text[0] = _T("Owner");
            String owner;
            attrs.getOwnerName(owner);
            text[1] = (TCHAR*)(const TCHAR*)owner;
            listview.insertLine(n++, text, 2);
        
            text[0] = _T("Domain");
            String domain;
            attrs.getOwnerDomain(domain);
            text[1] = (TCHAR*)(const TCHAR*)domain;
            listview.insertLine(n++, text, 2);
            rc = true;
        } catch (...) {
            ;//This has no version resource
        }
        return rc;        
    }

private:
    long size(Event& ev) {
        LPARAM lp = ev.getLParam();
        int w = LOWORD(lp);
        int h = HIWORD(lp);
        listview.move(4, 4, w-8, h-44, 1);
        ok.move(w-70, h-40+14, 50, 22, 1);
        return 0;
    }

};

}


Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.