suggestion for settings

Technical discussion about the NMDC and <a href="http://dcpp.net/ADC.html">ADC</A> protocol. The NMDC protocol is documented in the <a href="http://dcpp.net/wiki/">Wiki</a>, so feel free to refer to it.

Moderator: Moderators

dieselmachine
Posts: 36
Joined: 2003-01-20 03:22
Location: Rochester, NY, USA

suggestion for settings

Post by dieselmachine » 2003-06-03 00:35

I'm working on an anti-asshole client, and im trying to accomplish something as follows:

i have a bunch of bool toggles, for example:

if a client is misreporting share size, any or all of the following can be selected:
kick user
tempban user
permban user
log offense to logfile
public alert to chat
private alert to own window
block user from downloading from me

7 toggles. i dont want 7 different settings in the settings manager. What i was thinking was having a binary number like 1101100 which would allow me to check a position in the number for the yes/no option.

How would i do this? If i have 7 checkboxes in the settings page, how do i 'combine' them into a single number?

any better suggestions would be welcomed! :P

sarf
Posts: 382
Joined: 2003-01-24 10:43
Location: Sweden

Post by sarf » 2003-06-03 15:51

I would use checkboxes, then connect them to a function which updated a variable using the checkboxes state and bitshifting.

This is how you do it :

Create a few checkboxes - I will assume their names are IDC_MISREPORT_SHARE_1 to IDC_MISREPORT_SHARE_7.
In the message map of the pane, enter this :

Code: Select all

      COMMAND_HANDLER(IDC_MISREPORT_SHARE_1, BN_CLICKED, onUpdateMisreportShare)
      .
      .
      .
      COMMAND_HANDLER(IDC_MISREPORT_SHARE_7, BN_CLICKED, onUpdateMisreportShare)

Then add the following to the public part of the class :

Code: Select all

   LRESULT onUpdateMisreportShare(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
      updateMisreportShare();
      return 0;
   }

Add the int variable mMisreportShare to the class (I'd recommend setting it to zero as well as
And add the following to the class (public or private does not matter - I would prefer private, though) :

Code: Select all

   void updateMisreportShare() {
      mMisreportShare = 0;
      CButton btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_1);
      if(btn.GetCheck())
         mMisreportShare += 1;
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_2);
      if(btn.GetCheck())
         mMisreportShare += 2;
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_3);
      if(btn.GetCheck())
         mMisreportShare += 4;
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_4);
      if(btn.GetCheck())
         mMisreportShare += 8;
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_5);
      if(btn.GetCheck())
         mMisreportShare += 16;
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_6);
      if(btn.GetCheck())
         mMisreportShare += 32;
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_7);
      if(btn.GetCheck())
         mMisreportShare += 64;
   }
   
   void updateMisreportShareGUI() {
      mMisreportShare = SETTING(MISREPORT_SHARE); // <-- should be an int setting
      CButton btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_1);
      btn.SetCheck((mMisreportShare & 1) > 0);
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_2);
      btn.SetCheck((mMisreportShare & 2) > 0);
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_3);
      btn.SetCheck((mMisreportShare & 4) > 0);
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_4);
      btn.SetCheck((mMisreportShare & 8) > 0);
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_5);
      btn.SetCheck((mMisreportShare & 16) > 0);
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_6);
      btn.SetCheck((mMisreportShare & 32) > 0);
      btn = ::GetDlgItem(m_hWnd, IDC_MISREPORT_SHARE_7);
      btn.SetCheck((mMisreportShare & 64) > 0);
   }

Also, the following code must be added to the onInitDialog method :

Code: Select all

   updateMisreportShareGUI();

The write() method should have this appended to it :

Code: Select all

   SettingsManager::getInstance()->set(SettingsManager::MISREPORT_SHARE, mMisreportShare);


I assume that you have created a new IntSetting named MISREPORT_SHARE.

Good luck!

Sarf
---
If infinite rednecks fired infinite shotguns at an infinite number of road signs, they'd eventually create all the great literary works of the world in braille.

dieselmachine
Posts: 36
Joined: 2003-01-20 03:22
Location: Rochester, NY, USA

Dude

Post by dieselmachine » 2003-06-05 16:03

Thanks a ton for the help. Not only did you help me accomplish what i wanted to do, but I actually understand what each of those sections of code is doing. That helps a lot more in the long run. Before I started working on this program, I didn't know shit about c++, so this has been kind of an on-the-spot crash course... But that little bit of help is going to go a LOOOOOOONG way! Thanks again! You rock!

Who is online

Users browsing this forum: Google [Bot] and 0 guests