blob: 36b9b8667b640f0837dd3d8440febe28a7d9dbbc [file] [log] [blame]
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -05003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
32package org.sflphone.account;
33
Alexandre Lision8ad39592013-11-21 13:23:58 -050034import org.sflphone.fragments.FileExplorerDFragment;
35import org.sflphone.fragments.FileExplorerDFragment.onFileSelectedListener;
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050036import org.sflphone.model.Account;
37
38import android.app.Activity;
Alexandre Lision8ad39592013-11-21 13:23:58 -050039import android.preference.CheckBoxPreference;
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050040import android.preference.Preference;
41import android.preference.Preference.OnPreferenceChangeListener;
42import android.preference.Preference.OnPreferenceClickListener;
43import android.preference.PreferenceScreen;
44import android.util.Log;
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050045
Alexandre Lision8ad39592013-11-21 13:23:58 -050046public class TLSManager implements onFileSelectedListener {
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050047 PreferenceScreen mScreen;
48 private Account mAccount;
49 static Activity mContext;
50
51 public void onCreate(Activity con, PreferenceScreen preferenceScreen, Account acc) {
52 mContext = con;
53 mScreen = preferenceScreen;
54 mAccount = acc;
55
56 setDetails();
57 }
58
59 private void setDetails() {
60 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
61
Alexandre Lision8ad39592013-11-21 13:23:58 -050062 if (mScreen.getPreference(i) instanceof CheckBoxPreference) {
63 ((CheckBoxPreference) mScreen.getPreference(i)).setChecked(mAccount.getTlsDetails().getDetailBoolean(
64 mScreen.getPreference(i).getKey()));
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050065 } else {
Alexandre Lision8ad39592013-11-21 13:23:58 -050066 mScreen.getPreference(i).setSummary(mAccount.getTlsDetails().getDetailString(mScreen.getPreference(i).getKey()));
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050067 }
68
69 // ((CheckBoxPreference)
70 // mScreen.getPreference(i)).setChecked(mAccount.getSrtpDetails().getDetailBoolean(mScreen.getPreference(i).getKey()));
71 mScreen.getPreference(i).setOnPreferenceClickListener(new OnPreferenceClickListener() {
72
73 @Override
74 public boolean onPreferenceClick(Preference preference) {
Alexandre Lision8ad39592013-11-21 13:23:58 -050075 if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)
76 || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)
77 || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) {
78 FileExplorerDFragment dialog = FileExplorerDFragment.newInstance();
79 dialog.show(mContext.getFragmentManager(), "explorerdialog");
80 dialog.setOnFileSelectedListener(TLSManager.this, preference.getKey());
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050081 }
Alexandre Lision8ad39592013-11-21 13:23:58 -050082
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050083 return false;
84 }
85 });
86 }
87 }
88
89 public void setTLSListener() {
90 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
91 mScreen.getPreference(i).setOnPreferenceChangeListener(tlsListener);
92 }
93 }
94
95 private OnPreferenceChangeListener tlsListener = new OnPreferenceChangeListener() {
96
97 @Override
98 public boolean onPreferenceChange(Preference preference, Object newValue) {
99 Log.i("TLS", "Setting " + preference.getKey() + " to" + (Boolean) newValue);
100 mAccount.getTlsDetails().setDetailString(preference.getKey(), Boolean.toString((Boolean) newValue));
101 mAccount.notifyObservers();
102 return true;
103 }
104 };
105
Alexandre Lision8ad39592013-11-21 13:23:58 -0500106 @Override
107 public void onFileSelected(String path, String prefKey) {
108 mScreen.findPreference(prefKey).setSummary(path);
109 mAccount.getTlsDetails().setDetailString(prefKey, path);
110 mAccount.notifyObservers();
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -0500111 }
Alexandre Lision8ad39592013-11-21 13:23:58 -0500112
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -0500113}