Annotation of sbbs/src/sbbs3/ctrl/userlistformunit.cpp, revision 1.1.1.2

1.1.1.2 ! root        1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
        !             2: 
        !             3: /* $Id: UserListFormUnit.cpp,v 1.8 2011/09/03 06:02:47 rswindell Exp $ */
        !             4: 
        !             5: /****************************************************************************
        !             6:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             7:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !             8:  *                                                                                                                                                     *
        !             9:  * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            10:  *                                                                                                                                                     *
        !            11:  * This program is free software; you can redistribute it and/or                       *
        !            12:  * modify it under the terms of the GNU General Public License                         *
        !            13:  * as published by the Free Software Foundation; either version 2                      *
        !            14:  * of the License, or (at your option) any later version.                                      *
        !            15:  * See the GNU General Public License for more details: gpl.txt or                     *
        !            16:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
        !            17:  *                                                                                                                                                     *
        !            18:  * Anonymous FTP access to the most recent released source is available at     *
        !            19:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            20:  *                                                                                                                                                     *
        !            21:  * Anonymous CVS access to the development source and modification history     *
        !            22:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            23:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            24:  *     (just hit return, no password is necessary)                                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            26:  *                                                                                                                                                     *
        !            27:  * For Synchronet coding style and modification guidelines, see                                *
        !            28:  * http://www.synchro.net/source.html                                                                          *
        !            29:  *                                                                                                                                                     *
        !            30:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            31:  * format) via e-mail to [email protected]                                                                      *
        !            32:  *                                                                                                                                                     *
        !            33:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            34:  ****************************************************************************/
1.1       root       35: //---------------------------------------------------------------------------
                     36: 
                     37: #include "sbbs.h"
                     38: #include <vcl.h>
1.1.1.2 ! root       39: #include <vcl/Clipbrd.hpp>
1.1       root       40: #pragma hdrstop
                     41: 
                     42: #include "UserListFormUnit.h"
                     43: #include "MainFormUnit.h"
                     44: #include "userdat.h"
                     45: //---------------------------------------------------------------------------
                     46: #pragma package(smart_init)
                     47: #pragma resource "*.dfm"
                     48: TUserListForm *UserListForm;
                     49: //---------------------------------------------------------------------------
                     50: __fastcall TUserListForm::TUserListForm(TComponent* Owner)
                     51:     : TForm(Owner)
                     52: {
                     53: }
                     54: //---------------------------------------------------------------------------
                     55: void __fastcall TUserListForm::FormShow(TObject *Sender)
                     56: {
                     57:     char    str[128];
                     58:     int     i,last;
                     59:     user_t  user;
                     60:     TListItem*  Item;
                     61: 
                     62:     ColumnToSort=0;
                     63:     SortBackwards=false;
                     64:     Screen->Cursor=crAppStart;
                     65: 
                     66:     last=lastuser(&MainForm->cfg);
                     67:     ListView->AllocBy=last;
                     68: 
                     69:     ListView->Items->BeginUpdate();
                     70:     for(i=0;i<last;i++) {
                     71:         user.number=i+1;
                     72:         if(getuserdat(&MainForm->cfg,&user)!=0)
                     73:             continue;
                     74:         if(user.misc&DELETED)
                     75:             continue;
                     76:         Item=ListView->Items->Add();
                     77:         Item->Caption=AnsiString(i+1);
                     78:         Item->SubItems->Add(user.alias);
                     79:         Item->SubItems->Add(user.name);
                     80:         Item->SubItems->Add(user.level);
                     81:         Item->SubItems->Add((int)getage(&MainForm->cfg,user.birth));
                     82:         if(user.sex<=' ' || user.sex&0x80)  /* garbage? */
                     83:             str[0]=0;
                     84:         else
                     85:             sprintf(str,"%c",user.sex);
                     86:         Item->SubItems->Add(str);
                     87:         Item->SubItems->Add(user.location);
                     88:         Item->SubItems->Add(user.modem);
                     89:         Item->SubItems->Add(user.note);
                     90:         Item->SubItems->Add(user.comp);
                     91:         Item->SubItems->Add(user.phone);
                     92:         Item->SubItems->Add(user.netmail);
                     93:         Item->SubItems->Add(user.logons);
                     94:         Item->SubItems->Add(unixtodstr(&MainForm->cfg,user.firston,str));
                     95:         Item->SubItems->Add(unixtodstr(&MainForm->cfg,user.laston,str));
                     96:     }
                     97:     ListView->Items->EndUpdate();
                     98:     
                     99:     Screen->Cursor=crDefault;
                    100: }
                    101: //---------------------------------------------------------------------------
                    102: void __fastcall TUserListForm::ListViewColumnClick(TObject *Sender,
                    103:       TListColumn *Column)
                    104: {
                    105:     if(Column->Index == ColumnToSort)
                    106:         SortBackwards=!SortBackwards;
                    107:     else
                    108:         SortBackwards=false;
                    109:     ColumnToSort = Column->Index;
                    110:     ((TCustomListView *)Sender)->AlphaSort();
                    111: }
                    112: //---------------------------------------------------------------------------
                    113: void __fastcall TUserListForm::ListViewCompare(TObject *Sender,
                    114:       TListItem *Item1, TListItem *Item2, int Data, int &Compare)
                    115: {
                    116:     /* Decimal compare */
                    117:     if (ColumnToSort == 0 || ColumnToSort==3 || ColumnToSort==4
                    118:     || ColumnToSort == 12   /* logons */
                    119:     || ColumnToSort == 13   /* First On */
                    120:     || ColumnToSort == 14   /* Last On */
                    121:     ) {
                    122:         int num1, num2;
                    123: 
                    124:         if(ColumnToSort==0) {
                    125:             num1=Item1->Caption.ToIntDef(0);
                    126:             num2=Item2->Caption.ToIntDef(0);
                    127:         } else if(ColumnToSort>12) {    /* Date */
                    128:             int ix = ColumnToSort - 1;
                    129:             num1=dstrtounix(&MainForm->cfg
                    130:                 ,Item1->SubItems->Strings[ix].c_str());
                    131:             num2=dstrtounix(&MainForm->cfg
                    132:                 ,Item2->SubItems->Strings[ix].c_str());
                    133:         } else {
                    134:             int ix = ColumnToSort - 1;
                    135:             num1=Item1->SubItems->Strings[ix].ToIntDef(0);
                    136:             num2=Item2->SubItems->Strings[ix].ToIntDef(0);
                    137:         }
                    138:         if(SortBackwards)
                    139:             Compare=(num2-num1);
                    140:         else
                    141:             Compare=(num1-num2);
                    142:     } else {
                    143:         int ix = ColumnToSort - 1;
                    144:         if(SortBackwards)
                    145:             Compare = CompareText(Item2->SubItems->Strings[ix]
                    146:                 ,Item1->SubItems->Strings[ix]);
                    147:         else
                    148:             Compare = CompareText(Item1->SubItems->Strings[ix]
                    149:                 ,Item2->SubItems->Strings[ix]);
                    150:     }
                    151: }
                    152: //---------------------------------------------------------------------------
                    153: void __fastcall TUserListForm::FormClose(TObject *Sender,
                    154:       TCloseAction &Action)
                    155: {
                    156:     ListView->Items->BeginUpdate();
                    157:     ListView->Items->Clear();
                    158:     ListView->Items->EndUpdate();
                    159: }
                    160: //---------------------------------------------------------------------------
                    161: void __fastcall TUserListForm::EditUserPopupClick(TObject *Sender)
                    162: {
                    163:     char str[256];
                    164: 
                    165:     if(ListView->Selected==NULL)
                    166:         return;
                    167:     sprintf(str,"%sUSEREDIT %s %s"
                    168:         ,MainForm->cfg.exec_dir,MainForm->cfg.data_dir
                    169:         ,ListView->Selected->Caption.c_str());
                    170:     WinExec(str,SW_SHOWNORMAL);
                    171: }
                    172: //---------------------------------------------------------------------------
                    173: 
1.1.1.2 ! root      174: void __fastcall TUserListForm::ListViewKeyPress(TObject *Sender, char &Key)
        !           175: {
        !           176:     if(Key=='\r')
        !           177:         EditUserPopupClick(Sender);
        !           178: }
        !           179: //---------------------------------------------------------------------------
        !           180: static AnsiString ListItemString(TListItem* item)
        !           181: {
        !           182:     AnsiString str = item->Caption;
        !           183:     int i;
        !           184: 
        !           185:     for(i=0;i<item->SubItems->Count;i++)
        !           186:         str += "\t" + item->SubItems->Strings[i];
        !           187: 
        !           188:     return str + "\r\n";
        !           189: }
        !           190: //---------------------------------------------------------------------------
        !           191: void __fastcall TUserListForm::CopyPopupClick(TObject *Sender)
        !           192: {
        !           193:     if(ListView->Selected==NULL)
        !           194:         return;
        !           195:     Clipboard()->SetTextBuf(ListItemString(ListView->Selected).c_str());
        !           196: }
        !           197: //---------------------------------------------------------------------------
        !           198: void __fastcall TUserListForm::CopyAllPopupClick(TObject *Sender)
        !           199: {
        !           200:     AnsiString buf;
        !           201:     int i;
        !           202: 
        !           203:     for(i=0;i<ListView->Items->Count;i++)
        !           204:         buf += ListItemString(ListView->Items->Item[i]);
        !           205: 
        !           206:     Clipboard()->SetTextBuf(buf.c_str());
        !           207: }
        !           208: //---------------------------------------------------------------------------
        !           209: 
        !           210: void __fastcall TUserListForm::RefreshPopupClick(TObject *Sender)
        !           211: {
        !           212:     ListView->Items->BeginUpdate();
        !           213:     ListView->Items->Clear();
        !           214:     ListView->Items->EndUpdate();    
        !           215:     FormShow(Sender);
        !           216: }
        !           217: //---------------------------------------------------------------------------
        !           218: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.