Subversion Repositories tpanel

Rev

Rev 125 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 125 Rev 204
Line 42... Line 42...
42
#endif
42
#endif
43
 
43
 
44
using std::string;
44
using std::string;
45
using std::vector;
45
using std::vector;
46
 
46
 
-
 
47
static std::vector<std::string> mAllSounds;    // Cache
-
 
48
 
47
TSystemSound::TSystemSound(const string& path)
49
TSystemSound::TSystemSound(const string& path)
48
        : mPath(path)
50
        : mPath(path)
49
{
51
{
50
    DECL_TRACER("TSystemSound::TSystemSound(const string& path)");
52
    DECL_TRACER("TSystemSound::TSystemSound(const string& path)");
51
 
53
 
Line 143... Line 145...
143
    DECL_TRACER("TSystemSound::readAllSystemSounds()");
145
    DECL_TRACER("TSystemSound::readAllSystemSounds()");
144
 
146
 
145
    if (!mValid)
147
    if (!mValid)
146
        return false;
148
        return false;
147
 
149
 
148
    try
150
    if (mAllSounds.empty())
149
    {
151
    {
150
        for(auto& p: fs::directory_iterator(mPath))
152
        try
151
        {
153
        {
152
            string f = fs::path(p.path()).filename();
-
 
153
 
-
 
154
            if (f.at(0) == '.' || fs::is_directory(p.path()))
154
            for(auto& p: fs::directory_iterator(mPath))
155
                continue;
-
 
156
 
-
 
157
            if (fs::is_regular_file(p.path()))
-
 
158
            {
155
            {
159
                MSG_DEBUG("Found sound file " << f);
156
                string f = fs::path(p.path()).filename();
160
 
157
 
-
 
158
                if (f.at(0) == '.' || fs::is_directory(p.path()))
-
 
159
                    continue;
-
 
160
 
-
 
161
                if (fs::is_regular_file(p.path()))
-
 
162
                {
-
 
163
                    MSG_DEBUG("Found sound file " << f);
-
 
164
                    mAllSounds.push_back(f);
-
 
165
 
161
                if (startsWith(f, "singleBeep"))
166
                    if (startsWith(f, "singleBeep"))
162
                    mSinglePeeps.push_back(f);
167
                        mSinglePeeps.push_back(f);
163
                else if (startsWith(f, "doubleBeep"))
168
                    else if (startsWith(f, "doubleBeep"))
164
                    mDoubleBeeps.push_back(f);
169
                        mDoubleBeeps.push_back(f);
165
                else if (startsWith(f, "audio"))
170
                    else if (startsWith(f, "audio"))
166
                    mTestSound = f;
171
                        mTestSound = f;
167
                else if (startsWith(f, "docked"))
172
                    else if (startsWith(f, "docked"))
168
                    mDocked = f;
173
                        mDocked = f;
169
                else if (startsWith(f, "ringback"))
174
                    else if (startsWith(f, "ringback"))
170
                    mRingBack = f;
175
                        mRingBack = f;
171
                else if (startsWith(f, "ringtone"))
176
                    else if (startsWith(f, "ringtone"))
172
                    mRingTone = f;
177
                        mRingTone = f;
-
 
178
                }
173
            }
179
            }
174
        }
180
        }
-
 
181
        catch(std::exception& e)
-
 
182
        {
-
 
183
            MSG_ERROR("Error: " << e.what());
-
 
184
            return false;
-
 
185
        }
175
    }
186
    }
176
    catch(std::exception& e)
-
 
177
    {
187
    else
178
        MSG_ERROR("Error: " << e.what());
-
 
179
        return false;
188
        filterSounds();
180
    }
-
 
181
 
189
 
182
    if (mSinglePeeps.size() > 0)
190
    if (mSinglePeeps.size() > 0)
183
        std::sort(mSinglePeeps.begin(), mSinglePeeps.end());
191
        std::sort(mSinglePeeps.begin(), mSinglePeeps.end());
184
 
192
 
185
    if (mDoubleBeeps.size() > 0)
193
    if (mDoubleBeeps.size() > 0)
186
        std::sort(mDoubleBeeps.begin(), mDoubleBeeps.end());
194
        std::sort(mDoubleBeeps.begin(), mDoubleBeeps.end());
187
 
195
 
188
    return true;
196
    return true;
189
}
197
}
190
 
198
 
-
 
199
void TSystemSound::filterSounds()
-
 
200
{
-
 
201
    DECL_TRACER("TSystemSound::filterSounds()");
-
 
202
 
-
 
203
    if (mAllSounds.empty())
-
 
204
        return;
-
 
205
 
-
 
206
    vector<string>::iterator iter;
-
 
207
 
-
 
208
    for (iter = mAllSounds.begin(); iter != mAllSounds.end(); ++iter)
-
 
209
    {
-
 
210
        string f = *iter;
-
 
211
 
-
 
212
        if (startsWith(f, "singleBeep"))
-
 
213
            mSinglePeeps.push_back(f);
-
 
214
        else if (startsWith(f, "doubleBeep"))
-
 
215
            mDoubleBeeps.push_back(f);
-
 
216
        else if (startsWith(f, "audio"))
-
 
217
            mTestSound = f;
-
 
218
        else if (startsWith(f, "docked"))
-
 
219
            mDocked = f;
-
 
220
        else if (startsWith(f, "ringback"))
-
 
221
            mRingBack = f;
-
 
222
        else if (startsWith(f, "ringtone"))
-
 
223
            mRingTone = f;
-
 
224
    }
-
 
225
}
-
 
226
 
191
string TSystemSound::getFirstSingleBeep()
227
string TSystemSound::getFirstSingleBeep()
192
{
228
{
193
    DECL_TRACER("TSystemSound::getFirstSingleBeep()");
229
    DECL_TRACER("TSystemSound::getFirstSingleBeep()");
194
    mSinglePos = 0;
230
    mSinglePos = 0;
195
 
231